use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterProxyService method registerGatewayConfiguration.
public void registerGatewayConfiguration(Long stackId) {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
if (!stack.getCluster().hasGateway()) {
LOGGER.warn("Cluster {} with crn {} in environment {} not configured with Gateway (Knox). Not updating Cluster Proxy with Gateway url.", stack.getCluster().getName(), stack.getResourceCrn(), stack.getEnvironmentCrn());
return;
}
registerGateway(stack);
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ChangePrimaryGatewayService method primaryGatewayChanged.
public void primaryGatewayChanged(long stackId, String newPrimaryGatewayFQDN) throws CloudbreakException, TransactionExecutionException {
LOGGER.info("Update primary gateway ip");
Set<InstanceMetaData> imds = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
Optional<InstanceMetaData> formerPrimaryGateway = imds.stream().filter(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).findFirst();
Optional<InstanceMetaData> newPrimaryGateway = imds.stream().filter(imd -> imd.getDiscoveryFQDN() != null && imd.getDiscoveryFQDN().equals(newPrimaryGatewayFQDN)).findFirst();
if (newPrimaryGateway.isPresent() && formerPrimaryGateway.isPresent()) {
InstanceMetaData fpg = formerPrimaryGateway.get();
fpg.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
fpg.setServer(Boolean.FALSE);
transactionService.required(() -> {
instanceMetaDataService.save(fpg);
InstanceMetaData npg = newPrimaryGateway.get();
npg.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
npg.setServer(Boolean.TRUE);
instanceMetaDataService.save(npg);
Stack updatedStack = stackService.getByIdWithListsInTransaction(stackId);
String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(updatedStack);
Cluster cluster = updatedStack.getCluster();
cluster.setClusterManagerIp(gatewayIp);
LOGGER.info("Primary gateway IP has been updated to: '{}'", gatewayIp);
clusterService.save(cluster);
clusterPublicEndpointManagementService.changeGateway(updatedStack);
return null;
});
} else {
throw new CloudbreakException("Primary gateway change was not successful.");
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterUpgradeExistingUpgradeCommandValidationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeExistingUpgradeCommandValidationEvent> event) {
LOGGER.debug("Accepting Cluster upgrade existing upgradeCDH command validation event.");
ClusterUpgradeExistingUpgradeCommandValidationEvent request = event.getData();
Image targetImage = request.getImage();
Long stackId = request.getResourceId();
Stack stack = getStack(stackId);
ClusterApi connector = clusterApiConnectors.getConnector(stack);
Optional<ClusterManagerCommand> optionalUpgradeCommand = connector.clusterStatusService().findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER);
if (optionalUpgradeCommand.isEmpty()) {
LOGGER.debug("There is no existing upgradeCDH command, validation passed successfully");
return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
} else {
ClusterManagerCommand upgradeCommand = optionalUpgradeCommand.get();
if (upgradeCommand.getActive() || (!upgradeCommand.getSuccess() && upgradeCommand.getRetryable())) {
return validateIfExistingRuntimeMatchesTargetRuntime(stack, connector, targetImage);
} else {
LOGGER.debug("There is no retryable upgradeCDH command, validation passed successfully");
return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
}
}
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterUpgradeActions method clusterUpgradeFailedAction.
@Bean(name = "CLUSTER_UPGRADE_FAILED_STATE")
public Action<?, ?> clusterUpgradeFailedAction() {
return new AbstractClusterUpgradeAction<>(ClusterUpgradeFailedEvent.class) {
@Value("${cb.upgrade.failure.sync.sdx.enabled}")
private boolean syncAfterFailureEnabled;
@Override
protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeFailedEvent payload) {
Flow flow = getFlow(flowParameters.getFlowId());
Stack stack = stackService.getById(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
flow.setFlowFailed(payload.getException());
return ClusterUpgradeContext.from(flowParameters, payload);
}
@Override
protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeFailedEvent payload, Map<Object, Object> variables) {
clusterUpgradeService.handleUpgradeClusterFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
if (syncAfterFailureEnabled) {
LOGGER.debug("Starting syncing parcel and CM version from CM to DB.");
try {
Set<Image> candidateImages = new HashSet<>();
Optional.ofNullable(getCurrentImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
Optional.ofNullable(getTargetImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
ClusterUpgradeFailedCmSyncRequest cmSyncRequest = new ClusterUpgradeFailedCmSyncRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus(), candidateImages);
sendEvent(context, cmSyncRequest);
} catch (Exception e) {
LOGGER.warn("Error starting syncing CM version to DB, syncing skipped: ", e);
sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
}
} else {
LOGGER.debug("Syncing from CM to DB is not enabled.");
sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
}
}
@Override
protected Object getFailurePayload(ClusterUpgradeFailedEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
return null;
}
};
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class StartExternalDatabaseHandler method defaultFailureEvent.
@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<StartExternalDatabaseRequest> event) {
Stack stack = stackService.getById(event.getData().getResourceId());
LOGGER.error(String.format("Exception during DB 'start' for stack/cluster: %s", stack.getName()), e);
return startFailedEvent(stack, e);
}
Aggregations