@Test public void testGetNotExistedItem() throws Exception { String someKey = "someKey"; when(statusLine.getStatusCode()).thenReturn(404); assertNull(itemOpenApiService.getItem(someAppId, someEnv, someCluster, someNamespace, someKey)); }
public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class); } catch (Throwable ex) { if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) { return null; } throw new RuntimeException(String .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } }
ItemOpenApiService extends AbstractOpenApiService { public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class); } catch (Throwable ex) { if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) { return null; } throw new RuntimeException(String .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } } }
ItemOpenApiService extends AbstractOpenApiService { public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class); } catch (Throwable ex) { if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) { return null; } throw new RuntimeException(String .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } } ItemOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); }
ItemOpenApiService extends AbstractOpenApiService { public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class); } catch (Throwable ex) { if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) { return null; } throw new RuntimeException(String .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } } ItemOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); 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); }
ItemOpenApiService extends AbstractOpenApiService { public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) { if (Strings.isNullOrEmpty(clusterName)) { clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT; } if (Strings.isNullOrEmpty(namespaceName)) { namespaceName = ConfigConsts.NAMESPACE_APPLICATION; } checkNotEmpty(appId, "App id"); checkNotEmpty(env, "Env"); checkNotEmpty(key, "Item key"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key)); try (CloseableHttpResponse response = get(path)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class); } catch (Throwable ex) { if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) { return null; } throw new RuntimeException(String .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName, namespaceName, env), ex); } } ItemOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); 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);  }