use of com.squareup.okhttp.Call in project cloudbreak by hortonworks.
the class ClouderaManagerModificationServiceTest method testUpgradeClusterWhenPatchUpgradeAndPostUpgradeCommandIsAvailable.
@Test
void testUpgradeClusterWhenPatchUpgradeAndPostUpgradeCommandIsAvailable() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
TestUtil.clusterComponents(cluster);
when(clouderaManagerApiFactory.getParcelResourceApi(any())).thenReturn(parcelResourceApi);
when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi);
when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any())).thenReturn(clouderaManagerResourceApi);
when(clouderaManagerApiFactory.getMgmtServiceResourceApi(any())).thenReturn(mgmtServiceResourceApi);
when(clouderaManagerApiFactory.getServicesResourceApi(any())).thenReturn(servicesResourceApi);
BigDecimal apiCommandId = new BigDecimal(200);
// Mgmt Service restart
ApiCommandList apiCommandList = new ApiCommandList();
apiCommandList.setItems(new ArrayList<>());
when(mgmtServiceResourceApi.listActiveCommands("SUMMARY")).thenReturn(apiCommandList);
when(mgmtServiceResourceApi.restartCommand()).thenReturn(new ApiCommand().id(apiCommandId));
when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
// Start services if they are not running
ApiServiceList serviceList = new ApiServiceList();
ApiService service = new ApiService();
service.setServiceState(ApiServiceState.STOPPED);
serviceList.addItemsItem(service);
ApiCommand startCommand = mock(ApiCommand.class);
when(startCommand.getId()).thenReturn(apiCommandId);
when(servicesResourceApi.readServices(any(), any())).thenReturn(serviceList);
when(clustersResourceApi.startCommand(STACK_NAME)).thenReturn(startCommand);
// Post parcel activation
ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_5_1.getVersion());
// Restart services
when(clustersResourceApi.listActiveCommands(stack.getName(), "SUMMARY")).thenReturn(new ApiCommandList().items(List.of()));
when(clustersResourceApi.restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class))).thenReturn(new ApiCommand().id(apiCommandId));
when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
when(clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, apiClientMock)).thenReturn(success);
InstanceGroup instanceGroup = new InstanceGroup();
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setDiscoveryFQDN(HOSTNAME);
instanceGroup.setGroupName(GROUP_NAME);
instanceGroup.setInstanceMetaData(Set.of(instanceMetaData));
stack.setInstanceGroups(Set.of(instanceGroup));
when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi);
ApiHostList clusterHostsRef = new ApiHostList().items(List.of(new ApiHost().hostname(HOSTNAME)));
when(clustersResourceApi.listHosts(eq(STACK_NAME), eq(null), eq(null), eq(null))).thenReturn(clusterHostsRef);
when(clusterComponentProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_6_0.getVersion());
when(clouderaManagerApiFactory.getHostsResourceApi(any())).thenReturn(hostResourceApi);
Call call = mock(Call.class);
when(hostResourceApi.addTagsAsync(eq(HOSTNAME), any(), any())).thenReturn(call);
when(clouderaManagerApiClientProvider.getV45Client(any(), any(), any(), any())).thenReturn(apiClientMock);
underTest.upgradeClusterRuntime(cluster.getComponents(), true, Optional.empty());
verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmStartup(stack, apiClientMock);
verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmHostStatus(stack, apiClientMock);
verify(clouderaManagerParcelManagementService, times(1)).checkParcelApiAvailability(stack, apiClientMock);
verify(clouderaManagerParcelManagementService, times(1)).setParcelRepos(any(), eq(clouderaManagerResourceApi));
verify(clouderaManagerParcelManagementService, times(1)).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
verify(mgmtServiceResourceApi, times(1)).listActiveCommands("SUMMARY");
verify(mgmtServiceResourceApi, times(1)).restartCommand();
verify(clouderaManagerPollingServiceProvider, times(2)).startPollingCmServicesRestart(stack, apiClientMock, apiCommandId);
verify(clouderaManagerParcelManagementService, times(1)).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(clouderaManagerParcelManagementService, times(1)).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(clouderaManagerParcelManagementService, times(1)).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
verify(eventService, times(1)).fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_UPGRADE_START_POST_UPGRADE);
verify(clustersResourceApi, times(1)).startCommand(STACK_NAME);
verify(clouderaManagerUpgradeService, times(1)).callPostRuntimeUpgradeCommand(clustersResourceApi, stack, apiClientMock);
verify(clustersResourceApi, times(1)).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
verify(clustersResourceApi, times(2)).listActiveCommands(stack.getName(), "SUMMARY");
verify(clouderaManagerApiClientProvider, times(1)).getV45Client(any(), any(), any(), any());
ArgumentCaptor<List<ApiEntityTag>> entityTagListCaptor = ArgumentCaptor.forClass(List.class);
verify(hostResourceApi, times(1)).addTagsAsync(eq(HOSTNAME), entityTagListCaptor.capture(), any());
assertEquals("_cldr_cm_host_template_name", entityTagListCaptor.getValue().get(0).getName());
assertEquals(GROUP_NAME, entityTagListCaptor.getValue().get(0).getValue());
InOrder inOrder = Mockito.inOrder(clouderaManagerPollingServiceProvider, clouderaManagerParcelManagementService, clustersResourceApi, clouderaManagerUpgradeService, clouderaManagerApiClientProvider);
inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmStartup(stack, apiClientMock);
inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmHostStatus(stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).checkParcelApiAvailability(stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).setParcelRepos(any(), eq(clouderaManagerResourceApi));
inOrder.verify(clouderaManagerParcelManagementService).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
inOrder.verify(clouderaManagerParcelManagementService).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clouderaManagerParcelManagementService).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clouderaManagerParcelManagementService).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clustersResourceApi).startCommand(STACK_NAME);
inOrder.verify(clustersResourceApi).listActiveCommands(eq(stack.getName()), any());
inOrder.verify(clouderaManagerApiClientProvider).getV45Client(any(), any(), any(), any());
inOrder.verify(clouderaManagerUpgradeService).callPostRuntimeUpgradeCommand(eq(clustersResourceApi), eq(stack), eq(apiClientMock));
inOrder.verify(clustersResourceApi).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
}
use of com.squareup.okhttp.Call in project concord by walmartlabs.
the class ServerClient method getLog.
public byte[] getLog(String logFileName) throws ApiException {
Set<String> auths = client.getAuthentications().keySet();
String[] authNames = auths.toArray(new String[0]);
Call c = client.buildCall("/logs/" + logFileName, "GET", new ArrayList<>(), new ArrayList<>(), null, new HashMap<>(), new HashMap<>(), authNames, null);
Type t = new TypeToken<byte[]>() {
}.getType();
return client.<byte[]>execute(c, t).getData();
}
use of com.squareup.okhttp.Call in project apiman by apiman.
the class EnrichPre21ExportCommand method getSchema.
private Optional<ByteBuffer> getSchema(String orgId, String apiId, ApiVersionBean avb) throws IOException {
// {organizationId}/apis/{apiId}/versions/{version}/definition
HttpUrl getSchemaUrl = HttpUrl.parse(endpoint).newBuilder().addPathSegment("organizations").addPathSegment(orgId).addPathSegment("apis").addPathSegment(apiId).addPathSegment("versions").addPathSegment(avb.getVersion()).addPathSegment("definition").build();
Request request = buildRequest(getSchemaUrl);
Call exportCall = client.newCall(request);
Response getSchemaResponse = exportCall.execute();
if (getSchemaResponse.code() == 404) {
return Optional.empty();
}
checkStatusOk(getSchemaResponse);
return Optional.of(ByteBuffer.wrap(getSchemaResponse.body().bytes()));
}
use of com.squareup.okhttp.Call in project apiman by apiman.
the class EnrichPre21ExportCommand method checkVersion.
private void checkVersion() throws Exception {
HttpUrl statusUrl = HttpUrl.parse(endpoint).newBuilder().addPathSegment("system").addPathSegment("status").build();
Request request = buildRequest(statusUrl);
Call call = client.newCall(request);
Response response = call.execute();
checkStatusOk(response);
SystemStatusBean systemStatus = OBJECT_MAPPER.readValue(response.body().bytes(), SystemStatusBean.class);
if (!systemStatus.isUp()) {
throw new IllegalStateException("Server down " + systemStatus);
}
ComparableVersion systemVersion = new ComparableVersion(systemStatus.getVersion());
ComparableVersion maxVersion = new ComparableVersion("2.0.0.Final");
if (systemVersion.compareTo(maxVersion) > 0) {
throw new IllegalArgumentException("Server version is " + systemVersion + ". Any version after " + maxVersion + " does not need to apply this specific migration.");
}
}
use of com.squareup.okhttp.Call in project tbd-studio-se by Talend.
the class HadoopCMConfigurator method setAPIVersion.
private void setAPIVersion(ApiClient client) throws ApiException {
String requestPath = "/version";
String method = "GET";
Map<String, String> headerParams = new HashMap<String, String>();
String[] accepts = { "application/json" };
String accept = client.selectHeaderAccept(accepts);
if (accept != null)
headerParams.put("Accept", accept);
String[] contentTypes = new String[0];
String[] authNames = { "basic" };
String contentType = client.selectHeaderContentType(contentTypes);
headerParams.put("Content-Type", contentType);
Call c = client.buildCall(requestPath, method, null, null, headerParams, null, authNames, null);
Type returnType = (new TypeToken<String>() {
}).getType();
ApiResponse<String> version = client.execute(c, returnType);
if (version.getStatusCode() == 200) {
// highest version
client.setBasePath(client.getBasePath() + "/" + version.getData());
} else if (version.getStatusCode() == 404) {
// default version
client.setBasePath(client.getBasePath() + "/" + DEFAULT_API_VERSION);
} else {
// throw exception
throw new RuntimeException("Can't retrieve api version from " + client.getBasePath());
}
log.log(Level.INFO, "setAPIVersion, base path: " + client.getBasePath());
}
Aggregations