Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: let open api more easier to use and development #3943

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ApolloAppOpenApi {

List<OpenAppDTO> getAllApps();

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

List<OpenEnvClusterDTO> getEnvClusterInfo(String appId);

List<OpenAppDTO> getAuthorizedApps();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 ApolloClusterOpenApi {
OpenClusterDTO createCluster(String appId, String env, OpenClusterDTO openClusterDTO);
OpenClusterDTO getCluster(String appId, String env, String clusterName);
}
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.OpenItemDTO;

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

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, String key,
OpenItemDTO itemDTO, boolean createIfNotExists);

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 ApolloNamespaceOpenApi {

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

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

OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName,
String namespaceName);

OpenAppNamespaceDTO createNamespace(String appId, OpenAppNamespaceDTO appNamespaceDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;

/**
* combine other api together.
*
* @author wxq
*/
public interface ApolloOpenApi extends ApolloAppOpenApi, ApolloClusterOpenApi, ApolloItemOpenApi,
ApolloNamespaceOpenApi {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.ctrip.framework.apollo.openapi.client;

import com.ctrip.framework.apollo.openapi.api.ApolloOpenApi;
import com.ctrip.framework.apollo.openapi.client.constant.ApolloOpenApiConstants;
import com.ctrip.framework.apollo.openapi.client.service.AppOpenApiService;
import com.ctrip.framework.apollo.openapi.client.service.ClusterOpenApiService;
Expand Down Expand Up @@ -49,7 +50,7 @@
* For more information, please refer <a href="https://www.apolloconfig.com/#/zh/usage/apollo-open-api-platform">Apollo Wiki</a>.
*
*/
public class ApolloOpenApiClient {
public class ApolloOpenApiClient implements ApolloOpenApi {
private final String portalUrl;
private final String token;
private final AppOpenApiService appService;
Expand All @@ -76,13 +77,15 @@ private ApolloOpenApiClient(String portalUrl, String token, RequestConfig reques
/**
* Get the environment and cluster information
*/
@Override
public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
return appService.getEnvClusterInfo(appId);
}

/**
* Get all App information
*/
@Override
public List<OpenAppDTO> getAllApps() {
return appService.getAppsInfo(null);
}
Expand All @@ -92,20 +95,23 @@ public List<OpenAppDTO> getAllApps() {
*
* @return app's information
*/
@Override
public List<OpenAppDTO> getAuthorizedApps() {
return this.appService.getAuthorizedApps();
}

/**
* Get App information by app ids
*/
@Override
public List<OpenAppDTO> getAppsByIds(List<String> appIds) {
return appService.getAppsInfo(appIds);
}

/**
* Get the namespaces
*/
@Override
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
return namespaceService.getNamespaces(appId, env, clusterName);
}
Expand All @@ -115,36 +121,54 @@ public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clu
*
* @since 1.5.0
*/
@Override
public OpenClusterDTO getCluster(String appId, String env, String clusterName) {
return clusterService.getCluster(appId, env, clusterName);
}

/**
* Create the cluster
*
* Create the cluster. Suggest use {@link #createCluster(String, String, OpenClusterDTO)} instead.
* @since 1.5.0
*/
public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) {
return this.createCluster(openClusterDTO.getAppId(), env, openClusterDTO);
}

@Override
public OpenClusterDTO createCluster(String appId, String env, OpenClusterDTO openClusterDTO) {
if (null == appId) {
throw new IllegalArgumentException("appId cannot be null");
}
if (!appId.equals(openClusterDTO.getAppId())) {
throw new IllegalArgumentException("appId should same as in OpenClusterDTO");
}
return clusterService.createCluster(env, openClusterDTO);
}

/**
* Get the namespace
*/
@Override
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
return namespaceService.getNamespace(appId, env, clusterName, namespaceName);
}

/**
* Create the app namespace
* Create the app namespace. Suggest use {@link #createNamespace(String, OpenAppNamespaceDTO)} instead.
*/
public OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO) {
return namespaceService.createAppNamespace(appNamespaceDTO);
}

@Override
public OpenAppNamespaceDTO createNamespace(String appId, OpenAppNamespaceDTO appNamespaceDTO) {
Anilople marked this conversation as resolved.
Show resolved Hide resolved
return namespaceService.createAppNamespace(appNamespaceDTO);
}

/**
* Get the namespace lock
*/
@Override
public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) {
return namespaceService.getNamespaceLock(appId, env, clusterName, namespaceName);
}
Expand All @@ -156,6 +180,7 @@ public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String cl
*
* @since 1.2.0
*/
@Override
public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) {
return itemService.getItem(appId, env, clusterName, namespaceName, key);
}
Expand All @@ -164,30 +189,42 @@ public OpenItemDTO getItem(String appId, String env, String clusterName, String
* Add config
* @return the created config
*/
@Override
public OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName,
OpenItemDTO itemDTO) {
return itemService.createItem(appId, env, clusterName, namespaceName, itemDTO);
}

@Override
public void updateItem(String appId, String env, String clusterName, String namespaceName, String key,
OpenItemDTO itemDTO, boolean createIfNotExists) {
if (createIfNotExists) {
itemService.createOrUpdateItem(appId, env, clusterName, namespaceName, itemDTO);
} else {
itemService.updateItem(appId, env, clusterName, namespaceName, itemDTO);
}
}

/**
* Update config
*/
public void updateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
itemService.updateItem(appId, env, clusterName, namespaceName, itemDTO);
this.updateItem(appId, env, clusterName, namespaceName, itemDTO.getKey(), itemDTO, false);
}

/**
* Create config if not exists or update config if already exists
*/
public void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
itemService.createOrUpdateItem(appId, env, clusterName, namespaceName, itemDTO);
this.updateItem(appId, env, clusterName, namespaceName, itemDTO.getKey(), itemDTO, true);
}

/**
* Remove config
*
* @param operator the user who removes the item
*/
@Override
public void removeItem(String appId, String env, String clusterName, String namespaceName, String key,
String operator) {
itemService.removeItem(appId, env, clusterName, namespaceName, key, operator);
Expand All @@ -197,6 +234,8 @@ public void removeItem(String appId, String env, String clusterName, String name
* publish namespace
* @return the released configurations
*/
// TODO,
// @Override
public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName,
NamespaceReleaseDTO releaseDTO) {
return releaseService.publishNamespace(appId, env, clusterName, namespaceName, releaseDTO);
Expand All @@ -205,6 +244,8 @@ public OpenReleaseDTO publishNamespace(String appId, String env, String clusterN
/**
* @return the latest active release information or <code>null</code> if not found
*/
// TODO,
// @Override
public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName, String namespaceName) {
return releaseService.getLatestActiveRelease(appId, env, clusterName, namespaceName);
}
Expand All @@ -215,6 +256,8 @@ public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String cl
* @param operator the user who rollbacks the release
* @since 1.5.0
*/
// TODO,
// @Override
public void rollbackRelease(String env, long releaseId, String operator) {
releaseService.rollbackRelease(env, releaseId, operator);
}
Expand Down
Loading