Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Sep 16, 2021
2 parents eaa003f + 2455c0f commit 4b8f19a
Show file tree
Hide file tree
Showing 39 changed files with 1,647 additions and 309 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Apollo 1.10.0
* [Remove spring dependencies from internal code](https://github.com/apolloconfig/apollo/pull/3937)
* [Fix issue: ingress syntax](https://github.com/apolloconfig/apollo/pull/3933)
* [Support search by item](https://github.com/apolloconfig/apollo/pull/3977)
* [refactor: let open api more easier to use and development](https://github.com/apolloconfig/apollo/pull/3943)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId) {
return BeanUtils.transform(NamespaceDTO.class, namespace);
}

/**
* the returned content's size is not fixed. so please carefully used.
*/
@GetMapping("/namespaces/find-by-item")
public PageDTO<NamespaceDTO> findByItem(@RequestParam String itemKey, Pageable pageable) {
Page<Namespace> namespacePage = namespaceService.findByItem(itemKey, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public Namespace findOne(String appId, String clusterName, String namespaceName)
namespaceName);
}

/**
* the returned content's size is not fixed. so please carefully used.
*/
public Page<Namespace> findByItem(String itemKey, Pageable pageable) {
Page<Item> items = itemService.findItemsByKey(itemKey, pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,44 +344,4 @@ public interface StringFormatter<T> {
String format(T obj);
}

public static <T> String join(Collection<T> collection, String separator) {
return join(collection, separator, new StringFormatter<T>() {
@Override
public String format(T obj) {
return obj.toString();
}
});
}

public static <T> String join(Collection<T> collection, String separator,
StringFormatter<T> formatter) {
Iterator<T> iterator = collection.iterator();
// handle null, zero and one elements before building a buffer
if (iterator == null) {
return null;
}
if (!iterator.hasNext()) {
return EMPTY;
}
T first = iterator.next();
if (!iterator.hasNext()) {
return first == null ? "" : formatter.format(first);
}

// two or more elements
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
if (first != null) {
buf.append(formatter.format(first));
}

while (iterator.hasNext()) {
buf.append(separator);
T obj = iterator.next();
if (obj != null) {
buf.append(formatter.format(obj));
}
}

return buf.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ public void testIsNumeric() {
Assert.assertTrue(StringUtils.isNumeric("1"));
}

@Test
public void testJoin() {
Assert.assertEquals("", StringUtils.join(new ArrayList(), "1a 2b 3c"));

ArrayList collection = new ArrayList();
collection.add(null);
Assert.assertEquals("", StringUtils.join(collection, "1a 2b 3c"));

collection = new ArrayList();
collection.add(-2_147_483_648);
Assert.assertEquals("-2147483648", StringUtils.join(collection, "1a 2b 3c"));
}

@Test
public void testStartsWithIgnoreCase() {
Assert.assertFalse(StringUtils.startsWithIgnoreCase("A1B2C3", "BAZ"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import java.util.List;

/**
* @author wxq
*/
public interface AppOpenApiService {

List<OpenEnvClusterDTO> getEnvClusterInfo(String appId);

List<OpenAppDTO> getAllApps();

List<OpenAppDTO> getAppsInfo(List<String> appIds);

List<OpenAppDTO> getAuthorizedApps();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;

/**
* @author wxq
*/
public interface ClusterOpenApiService {

OpenClusterDTO getCluster(String appId, String env, String clusterName);

OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;

/**
* @author wxq
*/
public interface ItemOpenApiService {

OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName,
String key);

OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void updateItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO);

void removeItem(String appId, String env, String clusterName, String namespaceName, String key,
String operator);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
import java.util.List;

/**
* @author wxq
*/
public interface NamespaceOpenApiService {

OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName);

List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName);

OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO);

OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName,
String namespaceName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.openapi.api;

import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;

/**
* @author wxq
*/
public interface ReleaseOpenApiService {

OpenReleaseDTO publishNamespace(String appId, String env, String clusterName,
String namespaceName,
NamespaceReleaseDTO releaseDTO);

OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName,
String namespaceName);

void rollbackRelease(String env, long releaseId, String operator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
* Get all App information
*/
public List<OpenAppDTO> getAllApps() {
return appService.getAppsInfo(null);
return appService.getAllApps();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.ctrip.framework.apollo.openapi.client.exception;

public class ApolloOpenApiException extends RuntimeException {

private int status;
private final int status;

public ApolloOpenApiException(int status, String reason, String message) {
super(String.format("Request to apollo open api failed, status code: %d, reason: %s, message: %s", status, reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,21 @@
package com.ctrip.framework.apollo.openapi.client.service;

import com.ctrip.framework.apollo.openapi.client.exception.ApolloOpenApiException;
import com.ctrip.framework.apollo.openapi.client.url.OpenApiPathBuilder;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.escape.Escaper;
import com.google.common.net.UrlEscapers;
import com.google.gson.Gson;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.*;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

abstract class AbstractOpenApiService {
private static final Escaper pathEscaper = UrlEscapers.urlPathSegmentEscaper();
private static final Escaper queryParamEscaper = UrlEscapers.urlFormParameterEscaper();
import java.io.IOException;

abstract class AbstractOpenApiService {
private final String baseUrl;

protected final CloseableHttpClient client;
Expand All @@ -52,38 +43,30 @@ abstract class AbstractOpenApiService {
this.gson = gson;
}

protected CloseableHttpResponse get(String path) throws IOException {
HttpGet get = new HttpGet(String.format("%s/%s", baseUrl, path));
protected CloseableHttpResponse get(OpenApiPathBuilder path) throws IOException {
HttpGet get = new HttpGet(path.buildPath(baseUrl));

return execute(get);
}

protected CloseableHttpResponse post(String path, Object entity) throws IOException {
HttpPost post = new HttpPost(String.format("%s/%s", baseUrl, path));
protected CloseableHttpResponse post(OpenApiPathBuilder path, Object entity) throws IOException {
HttpPost post = new HttpPost(path.buildPath(baseUrl));

return execute(post, entity);
}

protected CloseableHttpResponse put(String path, Object entity) throws IOException {
HttpPut put = new HttpPut(String.format("%s/%s", baseUrl, path));
protected CloseableHttpResponse put(OpenApiPathBuilder path, Object entity) throws IOException {
HttpPut put = new HttpPut(path.buildPath(baseUrl));

return execute(put, entity);
}

protected CloseableHttpResponse delete(String path) throws IOException {
HttpDelete delete = new HttpDelete(String.format("%s/%s", baseUrl, path));
protected CloseableHttpResponse delete(OpenApiPathBuilder path) throws IOException {
HttpDelete delete = new HttpDelete(path.buildPath(baseUrl));

return execute(delete);
}

protected String escapePath(String path) {
return pathEscaper.escape(path);
}

protected String escapeParam(String param) {
return queryParamEscaper.escape(param);
}

private CloseableHttpResponse execute(HttpEntityEnclosingRequestBase requestBase, Object entity) throws IOException {
requestBase.setEntity(new StringEntity(gson.toJson(entity), ContentType.APPLICATION_JSON));

Expand All @@ -98,7 +81,6 @@ private CloseableHttpResponse execute(HttpUriRequest request) throws IOException
return response;
}


private void checkHttpResponseStatus(HttpResponse response) {
if (response.getStatusLine().getStatusCode() == 200) {
return;
Expand Down
Loading

0 comments on commit 4b8f19a

Please sign in to comment.