Search in sources :

Example 1 with ParcelResourceApi

use of com.cloudera.api.swagger.ParcelResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerParcelDecommissionService method removeParcels.

private ParcelOperationStatus removeParcels(ApiClient apiClient, ParcelResourceApi parcelResourceApi, Stack stack, Multimap<String, String> parcels) {
    ParcelOperationStatus removalStatus = parcels.entries().stream().map(parcel -> runSingleParcelCommand("REMOVE", stack.getName(), parcel, parcelResourceApi::removeDownloadCommand)).reduce(new ParcelOperationStatus(), ParcelOperationStatus::merge);
    Multimap<String, String> pollableParcels = filterForPollableParcels(parcels, removalStatus);
    ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmParcelDelete(stack, apiClient, pollableParcels);
    if (pollingResult.isExited()) {
        throw new CancellationException("Cluster was terminated while waiting for parcels deletion");
    } else if (pollingResult.isTimeout()) {
        throw new ClouderaManagerOperationFailedException("Timeout while Cloudera Manager deletes parcels.");
    }
    return removalStatus;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Logger(org.slf4j.Logger) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) Multimap(com.google.common.collect.Multimap) ApiException(com.cloudera.api.swagger.client.ApiException) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Multimaps(com.google.common.collect.Multimaps) Inject(javax.inject.Inject) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) HashMultimap(com.google.common.collect.HashMultimap) Collectors.toMap(java.util.stream.Collectors.toMap) Service(org.springframework.stereotype.Service) Map(java.util.Map) Entry(java.util.Map.Entry) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)

Example 2 with ParcelResourceApi

use of com.cloudera.api.swagger.ParcelResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerParcelDecommissionService method undistributeParcels.

private ParcelOperationStatus undistributeParcels(ApiClient apiClient, ParcelResourceApi parcelResourceApi, Stack stack, Multimap<String, String> parcels) {
    ParcelOperationStatus undistributeStatus = parcels.entries().stream().map(parcel -> runSingleParcelCommand("UNDISTRIBUTE", stack.getName(), parcel, parcelResourceApi::startRemovalOfDistributionCommand)).reduce(new ParcelOperationStatus(), ParcelOperationStatus::merge);
    Multimap<String, String> pollableParcels = filterForPollableParcels(parcels, undistributeStatus);
    ExtendedPollingResult pollingResult = clouderaManagerPollingServiceProvider.startPollingCmParcelStatus(stack, apiClient, pollableParcels, ParcelStatus.DOWNLOADED);
    if (pollingResult.isExited()) {
        throw new CancellationException("Cluster was terminated while waiting for parcels undistribution");
    } else if (pollingResult.isTimeout()) {
        throw new ClouderaManagerOperationFailedException("Timeout while Cloudera Manager undistribute parcels.");
    }
    return undistributeStatus;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Logger(org.slf4j.Logger) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) Multimap(com.google.common.collect.Multimap) ApiException(com.cloudera.api.swagger.client.ApiException) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) Multimaps(com.google.common.collect.Multimaps) Inject(javax.inject.Inject) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) HashMultimap(com.google.common.collect.HashMultimap) Collectors.toMap(java.util.stream.Collectors.toMap) Service(org.springframework.stereotype.Service) Map(java.util.Map) Entry(java.util.Map.Entry) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)

Example 3 with ParcelResourceApi

use of com.cloudera.api.swagger.ParcelResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerUpgradeParcelDistributeListenerTaskTest method testDoStatusCheckWhenParcelIsInState.

private void testDoStatusCheckWhenParcelIsInState(ParcelStatus parcelStatus, boolean expected) throws ApiException {
    ApiClient apiClient = mock(ApiClient.class);
    ParcelResourceApi parcelResourceApi = mock(ParcelResourceApi.class);
    when(clouderaManagerApiPojoFactory.getParcelResourceApi(apiClient)).thenReturn(parcelResourceApi);
    when(parcelResource.getProduct()).thenReturn("CDH");
    when(parcelResource.getClusterName()).thenReturn("clusterName");
    when(parcelResource.getVersion()).thenReturn("7.2.8");
    ApiParcel apiParcel = mock(ApiParcel.class);
    when(parcelResourceApi.readParcel("clusterName", "CDH", "7.2.8")).thenReturn(apiParcel);
    when(apiParcel.getStage()).thenReturn(parcelStatus.name());
    ClouderaManagerCommandPollerObject pollerObject = new ClouderaManagerCommandPollerObject(null, apiClient, BigDecimal.ONE);
    boolean result = underTest.doStatusCheck(pollerObject);
    Assertions.assertEquals(expected, result);
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ClouderaManagerCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerCommandPollerObject) ApiClient(com.cloudera.api.swagger.client.ApiClient)

Example 4 with ParcelResourceApi

use of com.cloudera.api.swagger.ParcelResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerUpgradeParcelDownloadListenerTaskTest method testDoStatusCheckWithParcelStatusShouldReturnTrue.

private void testDoStatusCheckWithParcelStatusShouldReturnTrue(ParcelStatus parcelStatus, boolean expected) throws ApiException {
    ApiClient apiClient = mock(ApiClient.class);
    ParcelResourceApi parcelResourceApi = mock(ParcelResourceApi.class);
    when(clouderaManagerApiPojoFactory.getParcelResourceApi(apiClient)).thenReturn(parcelResourceApi);
    when(parcelResource.getProduct()).thenReturn("CDH");
    when(parcelResource.getClusterName()).thenReturn("clusterName");
    when(parcelResource.getVersion()).thenReturn("7.2.8");
    ApiParcel apiParcel = mock(ApiParcel.class);
    when(parcelResourceApi.readParcel("clusterName", "CDH", "7.2.8")).thenReturn(apiParcel);
    when(apiParcel.getStage()).thenReturn(parcelStatus.name());
    ClouderaManagerCommandPollerObject pollerObject = new ClouderaManagerCommandPollerObject(null, apiClient, BigDecimal.ONE);
    boolean result = underTest.doStatusCheck(pollerObject);
    Assertions.assertEquals(expected, result);
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ClouderaManagerCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerCommandPollerObject) ApiClient(com.cloudera.api.swagger.client.ApiClient)

Example 5 with ParcelResourceApi

use of com.cloudera.api.swagger.ParcelResourceApi in project cloudbreak by hortonworks.

the class ClouderaManagerUpgradeParcelDistributeListenerTask method doStatusCheck.

@Override
protected boolean doStatusCheck(ClouderaManagerCommandPollerObject pollerObject) throws ApiException {
    ApiClient apiClient = pollerObject.getApiClient();
    ParcelResourceApi parcelResourceApi = clouderaManagerApiPojoFactory.getParcelResourceApi(apiClient);
    ApiParcel apiParcel = parcelResourceApi.readParcel(parcelResource.getClusterName(), parcelResource.getProduct(), parcelResource.getVersion());
    String parcelStage = apiParcel.getStage();
    if (!ParcelStatus.DISTRIBUTED.name().equals(parcelStage) && !ParcelStatus.ACTIVATED.name().equals(parcelStage) && !ParcelStatus.ACTIVATING.name().equals(parcelStage)) {
        LOGGER.warn("Expected parcel status is {}, received status is: {}", ParcelStatus.DISTRIBUTED.name(), parcelStage);
        return false;
    } else {
        return true;
    }
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) ApiClient(com.cloudera.api.swagger.client.ApiClient)

Aggregations

ParcelResourceApi (com.cloudera.api.swagger.ParcelResourceApi)10 ApiClient (com.cloudera.api.swagger.client.ApiClient)8 ApiException (com.cloudera.api.swagger.client.ApiException)5 ApiParcel (com.cloudera.api.swagger.model.ApiParcel)5 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)5 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)3 ParcelsResourceApi (com.cloudera.api.swagger.ParcelsResourceApi)3 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)3 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)3 ClustersResourceApi (com.cloudera.api.swagger.ClustersResourceApi)2 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 Multimaps (com.google.common.collect.Multimaps)2 ParcelStatus (com.sequenceiq.cloudbreak.cm.model.ParcelStatus)2 ClouderaManagerCommandPollerObject (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerCommandPollerObject)2 ClouderaManagerPollingServiceProvider (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider)2 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)2 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2