Skip to content

Commit 4b8f19a

Browse files
committed
resolve conflicts
2 parents eaa003f + 2455c0f commit 4b8f19a

File tree

39 files changed

+1647
-309
lines changed

39 files changed

+1647
-309
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Apollo 1.10.0
1414
* [Remove spring dependencies from internal code](https://github.com/apolloconfig/apollo/pull/3937)
1515
* [Fix issue: ingress syntax](https://github.com/apolloconfig/apollo/pull/3933)
1616
* [Support search by item](https://github.com/apolloconfig/apollo/pull/3977)
17+
* [refactor: let open api more easier to use and development](https://github.com/apolloconfig/apollo/pull/3943)
1718

1819
------------------
1920
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)

apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/NamespaceController.java

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public NamespaceDTO get(@PathVariable("namespaceId") Long namespaceId) {
9191
return BeanUtils.transform(NamespaceDTO.class, namespace);
9292
}
9393

94+
/**
95+
* the returned content's size is not fixed. so please carefully used.
96+
*/
9497
@GetMapping("/namespaces/find-by-item")
9598
public PageDTO<NamespaceDTO> findByItem(@RequestParam String itemKey, Pageable pageable) {
9699
Page<Namespace> namespacePage = namespaceService.findByItem(itemKey, pageable);

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public Namespace findOne(String appId, String clusterName, String namespaceName)
106106
namespaceName);
107107
}
108108

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

apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/StringUtils.java

-40
Original file line numberDiff line numberDiff line change
@@ -344,44 +344,4 @@ public interface StringFormatter<T> {
344344
String format(T obj);
345345
}
346346

347-
public static <T> String join(Collection<T> collection, String separator) {
348-
return join(collection, separator, new StringFormatter<T>() {
349-
@Override
350-
public String format(T obj) {
351-
return obj.toString();
352-
}
353-
});
354-
}
355-
356-
public static <T> String join(Collection<T> collection, String separator,
357-
StringFormatter<T> formatter) {
358-
Iterator<T> iterator = collection.iterator();
359-
// handle null, zero and one elements before building a buffer
360-
if (iterator == null) {
361-
return null;
362-
}
363-
if (!iterator.hasNext()) {
364-
return EMPTY;
365-
}
366-
T first = iterator.next();
367-
if (!iterator.hasNext()) {
368-
return first == null ? "" : formatter.format(first);
369-
}
370-
371-
// two or more elements
372-
StringBuilder buf = new StringBuilder(256); // Java default is 16, probably too small
373-
if (first != null) {
374-
buf.append(formatter.format(first));
375-
}
376-
377-
while (iterator.hasNext()) {
378-
buf.append(separator);
379-
T obj = iterator.next();
380-
if (obj != null) {
381-
buf.append(formatter.format(obj));
382-
}
383-
}
384-
385-
return buf.toString();
386-
}
387347
}

apollo-core/src/test/java/com/ctrip/framework/apollo/core/utils/StringUtilsTest.java

-13
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@ public void testIsNumeric() {
6767
Assert.assertTrue(StringUtils.isNumeric("1"));
6868
}
6969

70-
@Test
71-
public void testJoin() {
72-
Assert.assertEquals("", StringUtils.join(new ArrayList(), "1a 2b 3c"));
73-
74-
ArrayList collection = new ArrayList();
75-
collection.add(null);
76-
Assert.assertEquals("", StringUtils.join(collection, "1a 2b 3c"));
77-
78-
collection = new ArrayList();
79-
collection.add(-2_147_483_648);
80-
Assert.assertEquals("-2147483648", StringUtils.join(collection, "1a 2b 3c"));
81-
}
82-
8370
@Test
8471
public void testStartsWithIgnoreCase() {
8572
Assert.assertFalse(StringUtils.startsWithIgnoreCase("A1B2C3", "BAZ"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2021 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.api;
18+
19+
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
20+
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
21+
import java.util.List;
22+
23+
/**
24+
* @author wxq
25+
*/
26+
public interface AppOpenApiService {
27+
28+
List<OpenEnvClusterDTO> getEnvClusterInfo(String appId);
29+
30+
List<OpenAppDTO> getAllApps();
31+
32+
List<OpenAppDTO> getAppsInfo(List<String> appIds);
33+
34+
List<OpenAppDTO> getAuthorizedApps();
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2021 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.api;
18+
19+
import com.ctrip.framework.apollo.openapi.dto.OpenClusterDTO;
20+
21+
/**
22+
* @author wxq
23+
*/
24+
public interface ClusterOpenApiService {
25+
26+
OpenClusterDTO getCluster(String appId, String env, String clusterName);
27+
28+
OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2021 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.api;
18+
19+
import com.ctrip.framework.apollo.openapi.dto.OpenItemDTO;
20+
21+
/**
22+
* @author wxq
23+
*/
24+
public interface ItemOpenApiService {
25+
26+
OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName,
27+
String key);
28+
29+
OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName,
30+
OpenItemDTO itemDTO);
31+
32+
void updateItem(String appId, String env, String clusterName, String namespaceName,
33+
OpenItemDTO itemDTO);
34+
35+
void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName,
36+
OpenItemDTO itemDTO);
37+
38+
void removeItem(String appId, String env, String clusterName, String namespaceName, String key,
39+
String operator);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2021 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.api;
18+
19+
import com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO;
20+
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceDTO;
21+
import com.ctrip.framework.apollo.openapi.dto.OpenNamespaceLockDTO;
22+
import java.util.List;
23+
24+
/**
25+
* @author wxq
26+
*/
27+
public interface NamespaceOpenApiService {
28+
29+
OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName);
30+
31+
List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName);
32+
33+
OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO);
34+
35+
OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName,
36+
String namespaceName);
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2021 Apollo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package com.ctrip.framework.apollo.openapi.api;
18+
19+
import com.ctrip.framework.apollo.openapi.dto.NamespaceReleaseDTO;
20+
import com.ctrip.framework.apollo.openapi.dto.OpenReleaseDTO;
21+
22+
/**
23+
* @author wxq
24+
*/
25+
public interface ReleaseOpenApiService {
26+
27+
OpenReleaseDTO publishNamespace(String appId, String env, String clusterName,
28+
String namespaceName,
29+
NamespaceReleaseDTO releaseDTO);
30+
31+
OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName,
32+
String namespaceName);
33+
34+
void rollbackRelease(String env, long releaseId, String operator);
35+
}

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
8484
* Get all App information
8585
*/
8686
public List<OpenAppDTO> getAllApps() {
87-
return appService.getAppsInfo(null);
87+
return appService.getAllApps();
8888
}
8989

9090
/**

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/exception/ApolloOpenApiException.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
package com.ctrip.framework.apollo.openapi.client.exception;
1818

1919
public class ApolloOpenApiException extends RuntimeException {
20-
21-
private int status;
20+
private final int status;
2221

2322
public ApolloOpenApiException(int status, String reason, String message) {
2423
super(String.format("Request to apollo open api failed, status code: %d, reason: %s, message: %s", status, reason,

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/service/AbstractOpenApiService.java

+12-30
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,21 @@
1717
package com.ctrip.framework.apollo.openapi.client.service;
1818

1919
import com.ctrip.framework.apollo.openapi.client.exception.ApolloOpenApiException;
20+
import com.ctrip.framework.apollo.openapi.client.url.OpenApiPathBuilder;
2021
import com.google.common.base.Preconditions;
2122
import com.google.common.base.Strings;
22-
import com.google.common.escape.Escaper;
23-
import com.google.common.net.UrlEscapers;
2423
import com.google.gson.Gson;
25-
import java.io.IOException;
2624
import org.apache.http.HttpResponse;
2725
import org.apache.http.StatusLine;
28-
import org.apache.http.client.methods.CloseableHttpResponse;
29-
import org.apache.http.client.methods.HttpDelete;
30-
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
31-
import org.apache.http.client.methods.HttpGet;
32-
import org.apache.http.client.methods.HttpPost;
33-
import org.apache.http.client.methods.HttpPut;
34-
import org.apache.http.client.methods.HttpUriRequest;
26+
import org.apache.http.client.methods.*;
3527
import org.apache.http.entity.ContentType;
3628
import org.apache.http.entity.StringEntity;
3729
import org.apache.http.impl.client.CloseableHttpClient;
3830
import org.apache.http.util.EntityUtils;
3931

40-
abstract class AbstractOpenApiService {
41-
private static final Escaper pathEscaper = UrlEscapers.urlPathSegmentEscaper();
42-
private static final Escaper queryParamEscaper = UrlEscapers.urlFormParameterEscaper();
32+
import java.io.IOException;
4333

34+
abstract class AbstractOpenApiService {
4435
private final String baseUrl;
4536

4637
protected final CloseableHttpClient client;
@@ -52,38 +43,30 @@ abstract class AbstractOpenApiService {
5243
this.gson = gson;
5344
}
5445

55-
protected CloseableHttpResponse get(String path) throws IOException {
56-
HttpGet get = new HttpGet(String.format("%s/%s", baseUrl, path));
46+
protected CloseableHttpResponse get(OpenApiPathBuilder path) throws IOException {
47+
HttpGet get = new HttpGet(path.buildPath(baseUrl));
5748

5849
return execute(get);
5950
}
6051

61-
protected CloseableHttpResponse post(String path, Object entity) throws IOException {
62-
HttpPost post = new HttpPost(String.format("%s/%s", baseUrl, path));
52+
protected CloseableHttpResponse post(OpenApiPathBuilder path, Object entity) throws IOException {
53+
HttpPost post = new HttpPost(path.buildPath(baseUrl));
6354

6455
return execute(post, entity);
6556
}
6657

67-
protected CloseableHttpResponse put(String path, Object entity) throws IOException {
68-
HttpPut put = new HttpPut(String.format("%s/%s", baseUrl, path));
58+
protected CloseableHttpResponse put(OpenApiPathBuilder path, Object entity) throws IOException {
59+
HttpPut put = new HttpPut(path.buildPath(baseUrl));
6960

7061
return execute(put, entity);
7162
}
7263

73-
protected CloseableHttpResponse delete(String path) throws IOException {
74-
HttpDelete delete = new HttpDelete(String.format("%s/%s", baseUrl, path));
64+
protected CloseableHttpResponse delete(OpenApiPathBuilder path) throws IOException {
65+
HttpDelete delete = new HttpDelete(path.buildPath(baseUrl));
7566

7667
return execute(delete);
7768
}
7869

79-
protected String escapePath(String path) {
80-
return pathEscaper.escape(path);
81-
}
82-
83-
protected String escapeParam(String param) {
84-
return queryParamEscaper.escape(param);
85-
}
86-
8770
private CloseableHttpResponse execute(HttpEntityEnclosingRequestBase requestBase, Object entity) throws IOException {
8871
requestBase.setEntity(new StringEntity(gson.toJson(entity), ContentType.APPLICATION_JSON));
8972

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

101-
10284
private void checkHttpResponseStatus(HttpResponse response) {
10385
if (response.getStatusLine().getStatusCode() == 200) {
10486
return;

0 commit comments

Comments
 (0)