use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class TerminateExternalDatabaseHandler method accept.
@Override
public void accept(Event<TerminateExternalDatabaseRequest> terminateExternalDatabaseRequest) {
LOGGER.debug("In TerminateExternalDatabaseHandler.accept");
TerminateExternalDatabaseRequest request = terminateExternalDatabaseRequest.getData();
Stack stack = stackService.getById(request.getResourceId());
DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
Selectable result;
try {
if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Termination is not necessary.", stack.getName());
result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_DELETION_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_STARTED, "External database deletion in progress");
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
terminationService.terminateDatabase(stack.getCluster(), externalDatabase, environment, request.isForced());
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.AVAILABLE.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.AVAILABLE, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FINISHED, "External database deletion finished");
result = new TerminateExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_WAIT_TERMINATION_SUCCESS_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.info("Database termination polling exited before timeout. Cause: ", e);
result = terminateFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.info(String.format("Database termination poller stopped for stack: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.info(String.format("Database termination polling failed for stack: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
} catch (Exception e) {
LOGGER.error(String.format("Exception during DB termination for stack/cluster: %s", stack.getName()), e);
result = terminateFailedEvent(stack, e);
}
LOGGER.debug("Sending reactor notification for selector {}", result.selector());
eventBus.notify(result.selector(), new Event<>(terminateExternalDatabaseRequest.getHeaders(), result));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StopExternalDatabaseHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StopExternalDatabaseRequest> event) {
LOGGER.debug("In StopExternalDatabaseHandler.doAccept");
StopExternalDatabaseRequest request = event.getData();
Stack stack = stackService.getById(request.getResourceId());
DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
Selectable result;
try {
if (StackType.WORKLOAD != stack.getType()) {
LOGGER.debug("External database stop in Cloudbreak service is required for WORKLOAD stacks only.");
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else if (externalDatabase.isEmbedded()) {
LOGGER.info("External database for stack {} is not requested. Stop is not possible.", stack.getName());
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), null);
} else {
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_COMMANCED, "External database stop in progress");
stopService.stopDatabase(stack.getCluster(), externalDatabase, environment);
LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED.name());
stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FINISHED, "External database stop finished");
result = new StopExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STOPPED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
}
} catch (UserBreakException e) {
LOGGER.error("Database 'stop' polling exited before timeout. Cause: ", e);
result = stopFailedEvent(stack, e);
} catch (PollerStoppedException e) {
LOGGER.error(String.format("Database 'stop' poller stopped for stack: %s", stack.getName()), e);
result = stopFailedEvent(stack, e);
} catch (PollerException e) {
LOGGER.error(String.format("Database 'stop' polling failed for stack: %s", stack.getName()), e);
result = stopFailedEvent(stack, e);
}
return result;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StackCreationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<StackCreationWaitRequest> handlerEvent) {
StackCreationWaitRequest stackCreationWaitRequest = handlerEvent.getData();
Long sdxId = stackCreationWaitRequest.getResourceId();
String userId = stackCreationWaitRequest.getUserId();
Selectable response;
try {
LOGGER.debug("start polling stack creation process for id: {}", sdxId);
PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
StackV4Response stackV4Response = provisionerService.waitCloudbreakClusterCreation(sdxId, pollingConfig);
SdxCluster sdxCluster = sdxService.getById(sdxId);
sdxService.updateRuntimeVersionFromStackResponse(sdxCluster, stackV4Response);
setStackCreatedStatus(sdxId);
response = new StackCreationSuccessEvent(sdxId, userId);
} catch (UserBreakException userBreakException) {
LOGGER.error("Polling exited before timeout for SDX: {}. Cause: ", sdxId, userBreakException);
response = new SdxCreateFailedEvent(sdxId, userId, userBreakException);
} catch (PollerStoppedException pollerStoppedException) {
LOGGER.error("Poller stopped for SDX: {}", sdxId, pollerStoppedException);
response = new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack creation timed out after " + durationInMinutes + " minutes"));
} catch (PollerException exception) {
LOGGER.error("Polling failed for stack: {}", sdxId, exception);
response = new SdxCreateFailedEvent(sdxId, userId, exception);
} catch (Exception anotherException) {
LOGGER.error("Something wrong happened in stack creation wait phase", anotherException);
response = new SdxCreateFailedEvent(sdxId, userId, anotherException);
}
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StackStartStopService method updateInstancesToStopped.
private void updateInstancesToStopped(Stack stack, Collection<CloudVmInstanceStatus> instanceStatuses) {
Set<InstanceMetaData> allInstanceMetadataSet = instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(stack.getId());
for (InstanceMetaData metaData : allInstanceMetadataSet) {
Optional<CloudVmInstanceStatus> status = instanceStatuses.stream().filter(is -> is != null && is.getCloudInstance().getInstanceId() != null && is.getCloudInstance().getInstanceId().equals(metaData.getInstanceId())).findFirst();
if (status.isPresent()) {
CloudVmInstanceStatus cloudVmInstanceStatus = status.get();
com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus state = cloudVmInstanceStatus.getStatus() == InstanceStatus.STOPPED ? com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.STOPPED : FAILED;
metaData.setInstanceStatus(state);
}
}
instanceMetaDataService.saveAll(allInstanceMetadataSet);
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.
the class StackSyncService method updateInstances.
public void updateInstances(Stack stack, Iterable<InstanceMetaData> instanceMetaDataList, Collection<CloudVmInstanceStatus> instanceStatuses, SyncConfig syncConfig) {
try {
Map<InstanceSyncState, Integer> counts = initInstanceStateCounts();
Json imageJson = new Json(imageService.getImage(stack.getId()));
for (InstanceMetaData metaData : instanceMetaDataList) {
Optional<CloudVmInstanceStatus> status = instanceStatuses.stream().filter(is -> is != null && is.getCloudInstance().getInstanceId() != null && is.getCloudInstance().getInstanceId().equals(metaData.getInstanceId())).findFirst();
InstanceSyncState state;
if (status.isPresent()) {
CloudVmInstanceStatus cloudVmInstanceStatus = status.get();
CloudInstance cloudInstance = cloudVmInstanceStatus.getCloudInstance();
state = InstanceSyncState.getInstanceSyncState(cloudVmInstanceStatus.getStatus());
syncInstance(metaData, cloudInstance, imageJson);
} else {
state = InstanceSyncState.DELETED;
}
try {
syncInstanceStatusByState(stack, counts, metaData, state);
} catch (TransactionRuntimeExecutionException e) {
LOGGER.error("Can't sync instance status by state!", e);
}
}
handleSyncResult(stack, counts, syncConfig);
} catch (CloudbreakImageNotFoundException | IllegalArgumentException ex) {
LOGGER.info("Error during stack sync:", ex);
throw new CloudbreakServiceException("Stack sync failed", ex);
}
}
Aggregations