@Test(expected = RuntimeException.class) public void testPublishNamespaceWithError() throws Exception { String someReleaseTitle = "someReleaseTitle"; String someReleasedBy = "someReleasedBy"; NamespaceReleaseDTO namespaceReleaseDTO = new NamespaceReleaseDTO(); namespaceReleaseDTO.setReleaseTitle(someReleaseTitle); namespaceReleaseDTO.setReleasedBy(someReleasedBy); when(statusLine.getStatusCode()).thenReturn(400); releaseOpenApiService.publishNamespace(someAppId, someEnv, someCluster, someNamespace, namespaceReleaseDTO); }
public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName, NamespaceReleaseDTO releaseDTO) { 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(releaseDTO.getReleaseTitle(), "Release title"); checkNotEmpty(releaseDTO.getReleasedBy(), "Released by"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = post(path, releaseDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId, clusterName, env), ex); } }
ReleaseOpenApiService extends AbstractOpenApiService { public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName, NamespaceReleaseDTO releaseDTO) { 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(releaseDTO.getReleaseTitle(), "Release title"); checkNotEmpty(releaseDTO.getReleasedBy(), "Released by"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = post(path, releaseDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId, clusterName, env), ex); } } }
ReleaseOpenApiService extends AbstractOpenApiService { public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName, NamespaceReleaseDTO releaseDTO) { 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(releaseDTO.getReleaseTitle(), "Release title"); checkNotEmpty(releaseDTO.getReleasedBy(), "Released by"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = post(path, releaseDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId, clusterName, env), ex); } } ReleaseOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); }
ReleaseOpenApiService extends AbstractOpenApiService { public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName, NamespaceReleaseDTO releaseDTO) { 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(releaseDTO.getReleaseTitle(), "Release title"); checkNotEmpty(releaseDTO.getReleasedBy(), "Released by"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = post(path, releaseDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId, clusterName, env), ex); } } ReleaseOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); 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); }
ReleaseOpenApiService extends AbstractOpenApiService { public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName, NamespaceReleaseDTO releaseDTO) { 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(releaseDTO.getReleaseTitle(), "Release title"); checkNotEmpty(releaseDTO.getReleasedBy(), "Released by"); String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases", escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName)); try (CloseableHttpResponse response = post(path, releaseDTO)) { return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class); } catch (Throwable ex) { throw new RuntimeException(String .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId, clusterName, env), ex); } } ReleaseOpenApiService(CloseableHttpClient client, String baseUrl, Gson gson); 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);  }