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 all 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Apollo 1.10.0
* [remove ctrip profile](https://github.com/ctripcorp/apollo/pull/3920)
* [Remove spring dependencies from internal code](https://github.com/apolloconfig/apollo/pull/3937)
* [Fix issue: ingress syntax](https://github.com/apolloconfig/apollo/pull/3933)
* [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
@@ -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 @@ -28,7 +28,8 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

public class AppOpenApiService extends AbstractOpenApiService {
public class AppOpenApiService extends AbstractOpenApiService implements
com.ctrip.framework.apollo.openapi.api.AppOpenApiService {
private static final Type OPEN_ENV_CLUSTER_DTO_LIST_TYPE = new TypeToken<List<OpenEnvClusterDTO>>() {
}.getType();
private static final Type OPEN_APP_DTO_LIST_TYPE = new TypeToken<List<OpenAppDTO>>() {
Expand All @@ -38,6 +39,7 @@ public AppOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson)
super(client, baseUrl, gson);
}

@Override
public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
checkNotEmpty(appId, "App id");

Expand All @@ -52,6 +54,12 @@ public List<OpenEnvClusterDTO> getEnvClusterInfo(String appId) {
}
}

@Override
public List<OpenAppDTO> getAllApps() {
return this.getAppsInfo(null);
}

@Override
public List<OpenAppDTO> getAppsInfo(List<String> appIds) {
OpenApiPathBuilder pathBuilder = OpenApiPathBuilder.newBuilder()
.customResource("apps");
Expand All @@ -68,6 +76,7 @@ public List<OpenAppDTO> getAppsInfo(List<String> appIds) {
}
}

@Override
public List<OpenAppDTO> getAuthorizedApps() {
OpenApiPathBuilder pathBuilder = OpenApiPathBuilder.newBuilder()
.customResource("apps/authorized");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

public class ClusterOpenApiService extends AbstractOpenApiService {
public class ClusterOpenApiService extends AbstractOpenApiService implements
com.ctrip.framework.apollo.openapi.api.ClusterOpenApiService {

public ClusterOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson) {
super(client, baseUrl, gson);
}

@Override
public OpenClusterDTO getCluster(String appId, String env, String clusterName) {
checkNotEmpty(appId, "App id");
checkNotEmpty(env, "Env");
Expand All @@ -52,6 +54,7 @@ public OpenClusterDTO getCluster(String appId, String env, String clusterName) {
}
}

@Override
public OpenClusterDTO createCluster(String env, OpenClusterDTO openClusterDTO) {
checkNotEmpty(openClusterDTO.getAppId(), "App id");
checkNotEmpty(env, "Env");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

public class ItemOpenApiService extends AbstractOpenApiService {
public class ItemOpenApiService extends AbstractOpenApiService implements
com.ctrip.framework.apollo.openapi.api.ItemOpenApiService {

public ItemOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson) {
super(client, baseUrl, gson);
}

@Override
public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down Expand Up @@ -64,6 +66,7 @@ public OpenItemDTO getItem(String appId, String env, String clusterName, String
}
}

@Override
public OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down Expand Up @@ -93,6 +96,7 @@ public OpenItemDTO createItem(String appId, String env, String clusterName, Stri
}
}

@Override
public void updateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down Expand Up @@ -121,6 +125,7 @@ public void updateItem(String appId, String env, String clusterName, String name
}
}

@Override
public void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down Expand Up @@ -154,6 +159,7 @@ public void createOrUpdateItem(String appId, String env, String clusterName, Str
}
}

@Override
public void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

public class NamespaceOpenApiService extends AbstractOpenApiService {
public class NamespaceOpenApiService extends AbstractOpenApiService implements
com.ctrip.framework.apollo.openapi.api.NamespaceOpenApiService {
private static final Type OPEN_NAMESPACE_DTO_LIST_TYPE = new TypeToken<List<OpenNamespaceDTO>>() {
}.getType();

public NamespaceOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson) {
super(client, baseUrl, gson);
}

@Override
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand All @@ -65,6 +67,7 @@ public OpenNamespaceDTO getNamespace(String appId, String env, String clusterNam
}
}

@Override
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand All @@ -87,6 +90,7 @@ public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clu
}
}

@Override
public OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDTO) {
checkNotEmpty(appNamespaceDTO.getAppId(), "App id");
checkNotEmpty(appNamespaceDTO.getName(), "Name");
Expand All @@ -109,6 +113,7 @@ public OpenAppNamespaceDTO createAppNamespace(OpenAppNamespaceDTO appNamespaceDT
}
}

@Override
public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;

public class ReleaseOpenApiService extends AbstractOpenApiService {
public class ReleaseOpenApiService extends AbstractOpenApiService implements
com.ctrip.framework.apollo.openapi.api.ReleaseOpenApiService {

public ReleaseOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson) {
super(client, baseUrl, gson);
}

@Override
public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName,
NamespaceReleaseDTO releaseDTO) {
if (Strings.isNullOrEmpty(clusterName)) {
Expand Down Expand Up @@ -62,6 +64,7 @@ public OpenReleaseDTO publishNamespace(String appId, String env, String clusterN
}
}

@Override
public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName, String namespaceName) {
if (Strings.isNullOrEmpty(clusterName)) {
clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
Expand Down Expand Up @@ -89,6 +92,7 @@ public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String cl
}
}

@Override
public void rollbackRelease(String env, long releaseId, String operator) {
checkNotEmpty(env, "Env");
checkNotEmpty(operator, "Operator");
Expand Down
Loading