use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ReactorNotifier method notify.
public FlowIdentifier notify(Long stackId, String selector, Acceptable acceptable, Function<Long, Stack> getStackFn) {
Event<Acceptable> event = eventFactory.createEventWithErrHandler(eventParameterFactory.createEventParameters(stackId), acceptable);
Stack stack = getStackFn.apply(event.getData().getResourceId());
Optional.ofNullable(stack).map(Stack::getStatus).ifPresent(isTriggerAllowedInMaintenance(selector));
reactorReporter.logInfoReport();
reactor.notify(selector, event);
return checkFlowStatus(event, stack.getName());
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class CcmKeyDeregisterAction method createRequest.
@Override
protected CcmKeyDeregisterRequest createRequest(StackTerminationContext context) {
Stack stack = context.getStack();
String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
String actorCrn = Objects.requireNonNull(userCrn, "userCrn is null");
String accountId = ThreadBasedUserCrnProvider.getAccountId();
String keyId = CcmResourceUtil.getKeyId(stack.getResourceCrn());
return new CcmKeyDeregisterRequest(stack.getId(), actorCrn, accountId, keyId, stack.getTunnel());
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class StackUpscaleActions method finishExtendMetadata.
@Bean(name = "EXTEND_METADATA_FINISHED_STATE")
public Action<?, ?> finishExtendMetadata() {
return new AbstractStackUpscaleAction<>(CollectMetadataResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, CollectMetadataResult payload, Map<Object, Object> variables) throws TransactionExecutionException {
Integer adjustment = context.getHostGroupWithAdjustment().values().stream().reduce(0, Integer::sum);
Set<String> upscaleCandidateAddresses = stackUpscaleService.finishExtendMetadata(context.getStack(), adjustment, payload);
variables.put(UPSCALE_CANDIDATE_ADDRESSES, upscaleCandidateAddresses);
Set<String> hostGroups = context.getHostGroupWithAdjustment().keySet();
List<InstanceGroup> scaledInstanceGroups = instanceGroupService.findByStackIdAndInstanceGroupNames(payload.getResourceId(), hostGroups);
boolean gatewayWasUpscaled = scaledInstanceGroups.stream().anyMatch(instanceGroup -> InstanceGroupType.GATEWAY.equals(instanceGroup.getInstanceGroupType()));
if (gatewayWasUpscaled) {
LOGGER.info("Gateway type instance group");
Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
if (null == gatewayMetaData) {
throw new CloudbreakServiceException("Could not get gateway instance metadata from the cloud provider.");
}
DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
LOGGER.info("Send GetSSHFingerprintsRequest because we need to collect SSH fingerprints");
Selectable sshFingerPrintReq = new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
sendEvent(context, sshFingerPrintReq);
} else {
StackEvent bootstrapPayload = new StackEvent(context.getStack().getId());
sendEvent(context, StackUpscaleEvent.BOOTSTRAP_NEW_NODES_EVENT.event(), bootstrapPayload);
}
}
};
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class StackUpscaleActions method addInstances.
@Bean(name = "ADD_INSTANCES_STATE")
public Action<?, ?> addInstances() {
return new AbstractStackUpscaleAction<>(UpscaleStackValidationResult.class) {
@Override
protected void doExecute(StackScalingFlowContext context, UpscaleStackValidationResult payload, Map<Object, Object> variables) {
sendEvent(context);
}
@Override
protected Selectable createRequest(StackScalingFlowContext context) {
Map<String, Integer> hostGroupWithInstanceCountToCreate = getHostGroupsWithInstanceCountToCreate(context);
Stack updatedStack = instanceMetaDataService.saveInstanceAndGetUpdatedStack(context.getStack(), hostGroupWithInstanceCountToCreate, context.getHostgroupWithHostnames(), true, context.isRepair(), context.getStackNetworkScaleDetails());
List<CloudResource> resources = context.getStack().getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
CloudStack updatedCloudStack = cloudStackConverter.convert(updatedStack);
AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = context.getAdjustmentTypeWithThreshold();
if (adjustmentTypeWithThreshold == null) {
Integer exactNumber = hostGroupWithInstanceCountToCreate.values().stream().reduce(0, Integer::sum);
adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, exactNumber.longValue());
}
LOGGER.info("Adjustment type with threshold for upscale request: {}", adjustmentTypeWithThreshold);
return new UpscaleStackRequest<UpscaleStackResult>(context.getCloudContext(), context.getCloudCredential(), updatedCloudStack, resources, adjustmentTypeWithThreshold);
}
};
}
use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.
the class ClusterCredentialChangeHandler method accept.
@Override
public void accept(Event<ClusterCredentialChangeRequest> event) {
ClusterCredentialChangeRequest request = event.getData();
ClusterCredentialChangeResult result;
try {
Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
ClusterSecurityService clusterSecurityService = clusterApiConnectors.getConnector(stack).clusterSecurityService();
switch(request.getType()) {
case REPLACE:
clusterSecurityService.replaceUserNamePassword(request.getUser(), request.getPassword());
break;
case UPDATE:
clusterSecurityService.updateUserNamePassword(request.getPassword());
break;
default:
throw new UnsupportedOperationException("Ambari credential update request not supported: " + request.getType());
}
result = new ClusterCredentialChangeResult(request);
} catch (Exception e) {
result = new ClusterCredentialChangeResult(e.getMessage(), e, request);
}
eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Aggregations