Search in sources :

Example 26 with Call

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));
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) Call(com.squareup.okhttp.Call) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) InOrder(org.mockito.InOrder) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ApiService(com.cloudera.api.swagger.model.ApiService) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArrayList(java.util.ArrayList) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiHost(com.cloudera.api.swagger.model.ApiHost) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 27 with Call

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();
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type)

Example 28 with Call

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()));
}
Also used : Response(com.squareup.okhttp.Response) Call(com.squareup.okhttp.Call) Request(com.squareup.okhttp.Request) HttpUrl(com.squareup.okhttp.HttpUrl)

Example 29 with Call

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.");
    }
}
Also used : Response(com.squareup.okhttp.Response) Call(com.squareup.okhttp.Call) Request(com.squareup.okhttp.Request) SystemStatusBean(io.apiman.manager.api.beans.system.SystemStatusBean) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) HttpUrl(com.squareup.okhttp.HttpUrl)

Example 30 with Call

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());
}
Also used : Call(com.squareup.okhttp.Call) Type(java.lang.reflect.Type) HashMap(java.util.HashMap) TypeToken(com.google.gson.reflect.TypeToken)

Aggregations

Call (com.squareup.okhttp.Call)46 Type (java.lang.reflect.Type)28 Request (com.squareup.okhttp.Request)13 Response (com.squareup.okhttp.Response)13 OkHttpClient (com.squareup.okhttp.OkHttpClient)9 PaymentDetails (jp.ne.paypay.model.PaymentDetails)8 RequestBody (com.squareup.okhttp.RequestBody)5 IOException (java.io.IOException)5 HttpUrl (com.squareup.okhttp.HttpUrl)4 HashMap (java.util.HashMap)4 ReverseCashbackDetails (jp.ne.paypay.model.ReverseCashbackDetails)4 TypeToken (com.google.gson.reflect.TypeToken)3 NotDataResponse (jp.ne.paypay.model.NotDataResponse)3 Base64 (org.apache.commons.codec.binary.Base64)3 Pair (jp.ne.paypay.Pair)2 Request (com.android.volley.Request)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiCommandList (com.cloudera.api.swagger.model.ApiCommandList)1 ApiHost (com.cloudera.api.swagger.model.ApiHost)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)1