Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
wuguanyu committed Sep 1, 2023
2 parents 73082c0 + e68a731 commit 710aa76
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 5 deletions.
11 changes: 6 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ Release Notes.
Apollo Java 2.2.0

------------------
[refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
[Add JUnit5 extension support for apollo mock server.](https://github.com/apolloconfig/apollo-java/pull/25)
[Support concurrent loading of Config for different namespaces.](https://github.com/apolloconfig/apollo-java/pull/31)
[Fix snakeyaml 2.x compatibility issues](https://github.com/apolloconfig/apollo-java/pull/35)
[Support other data sources like spring cloud config initialize system properties](https://github.com/apolloconfig/apollo-java/pull/37)
* [refactor(apollo-client): Optimize the exception message when failing to retrieve configuration information.](https://github.com/apolloconfig/apollo-java/pull/22)
* [Add JUnit5 extension support for apollo mock server.](https://github.com/apolloconfig/apollo-java/pull/25)
* [Support concurrent loading of Config for different namespaces.](https://github.com/apolloconfig/apollo-java/pull/31)
* [Fix snakeyaml 2.x compatibility issues](https://github.com/apolloconfig/apollo-java/pull/35)
* [feat(openapi): create app](https://github.com/apolloconfig/apollo-java/pull/32)
* [Support other data sources like spring cloud config initialize system properties](https://github.com/apolloconfig/apollo-java/pull/37)

------------------
All issues and pull requests are [here](https://github.com/apolloconfig/apollo-java/milestone/2?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public void initialize(ConfigurableApplicationContext context) {
* @param environment
*/
protected void initialize(ConfigurableEnvironment environment) {

// need to initialize system properties like app.id again in case they are configured in external data sources like spring cloud config
initializeSystemProperty(environment);

final ConfigUtil configUtil = ApolloInjector.getInstance(ConfigUtil.class);
if (environment.getPropertySources().contains(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
//already initialized, replay the logs that were printed before the logging system was initialized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.ctrip.framework.apollo.openapi.api;

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

Expand All @@ -25,6 +26,10 @@
*/
public interface AppOpenApiService {

default void createApp(OpenCreateAppDTO req) {
throw new UnsupportedOperationException();

Check warning on line 30 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/AppOpenApiService.java

View check run for this annotation

Codecov / codecov/patch

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/api/AppOpenApiService.java#L30

Added line #L30 was not covered by tests
}

List<OpenEnvClusterDTO> getEnvClusterInfo(String appId);

List<OpenAppDTO> getAllApps();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ private ApolloOpenApiClient(String portalUrl, String token, RequestConfig reques
releaseService = new ReleaseOpenApiService(client, baseUrl, GSON);
}

public void createApp(OpenCreateAppDTO req) {
appService.createApp(req);
}

Check warning on line 70 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/client/ApolloOpenApiClient.java

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L69 - L70 were not covered by tests

/**
* Get the environment and cluster information
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ private void checkHttpResponseStatus(HttpResponse response) {
throw new ApolloOpenApiException(status.getStatusCode(), status.getReasonPhrase(), message);
}

protected void checkNotNull(Object value, String name) {
Preconditions.checkArgument(null != value, name + " should not be null");
}

protected void checkNotEmpty(String value, String name) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(value), name + " should not be null or empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.ctrip.framework.apollo.openapi.client.url.OpenApiPathBuilder;
import com.ctrip.framework.apollo.openapi.dto.OpenAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenCreateAppDTO;
import com.ctrip.framework.apollo.openapi.dto.OpenEnvClusterDTO;
import com.google.common.base.Joiner;
import com.google.gson.Gson;
Expand All @@ -39,6 +40,24 @@ public AppOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson)
super(client, baseUrl, gson);
}

@Override
public void createApp(OpenCreateAppDTO req) {
OpenAppDTO app = req.getApp();
checkNotNull(app, "App");
checkNotEmpty(app.getAppId(), "App id");
checkNotEmpty(app.getName(), "App name");
OpenApiPathBuilder pathBuilder = OpenApiPathBuilder.newBuilder()
.customResource("apps");

try (CloseableHttpResponse response = post(pathBuilder, req)) {
gson.fromJson(EntityUtils.toString(response.getEntity()), void.class);
} catch (Throwable ex) {
throw new RuntimeException(
String.format("Create app: %s for appId: %s failed", app.getName(),
app.getAppId()), ex);
}
}

@Override
public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
checkNotEmpty(appId, "App id");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2022 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.dto;

import java.util.Set;

public class OpenCreateAppDTO {

/**
* when {@code assignAppRoleToSelf} is true,
* you can do anything with the app by current token!
*/
private boolean assignAppRoleToSelf;

/**
* The application owner has project administrator permission by default.
* <p>
* Administrators can create namespace, cluster, and assign user permissions
*/
private Set<String> admins;

private OpenAppDTO app;

public boolean isAssignAppRoleToSelf() {
return assignAppRoleToSelf;

Check warning on line 39 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java

View check run for this annotation

Codecov / codecov/patch

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java#L39

Added line #L39 was not covered by tests
}

public void setAssignAppRoleToSelf(boolean assignAppRoleToSelf) {
this.assignAppRoleToSelf = assignAppRoleToSelf;
}

Check warning on line 44 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java

View check run for this annotation

Codecov / codecov/patch

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java#L43-L44

Added lines #L43 - L44 were not covered by tests

public Set<String> getAdmins() {
return admins;

Check warning on line 47 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java

View check run for this annotation

Codecov / codecov/patch

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java#L47

Added line #L47 was not covered by tests
}

public void setAdmins(Set<String> admins) {
this.admins = admins;
}

public OpenAppDTO getApp() {
return app;
}

public void setApp(OpenAppDTO app) {
this.app = app;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("OpenCreateAppDTO{");
sb.append("assignAppRoleToSelf='").append(assignAppRoleToSelf).append('\'');
sb.append(", admins='").append(admins).append('\'');
sb.append(", app=").append(app);
sb.append('}');
return sb.toString();

Check warning on line 69 in apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java

View check run for this annotation

Codecov / codecov/patch

apollo-openapi/src/main/java/com/ctrip/framework/apollo/openapi/dto/OpenCreateAppDTO.java#L64-L69

Added lines #L64 - L69 were not covered by tests
}
}
Loading

0 comments on commit 710aa76

Please sign in to comment.