use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceTerminationService method finishInstanceTermination.
public void finishInstanceTermination(InstanceTerminationContext context, RemoveInstanceResult payload) {
Stack stack = context.getStack();
List<InstanceMetaData> instanceMetaDataList = context.getInstanceMetaDataList();
for (InstanceMetaData instanceMetaData : instanceMetaDataList) {
String instanceId = instanceMetaData.getInstanceId();
InstanceGroup instanceGroup = stack.getInstanceGroupByInstanceGroupId(instanceMetaData.getInstanceGroup().getId());
stackScalingService.updateRemovedResourcesState(stack, Collections.singleton(instanceId), instanceGroup);
if (stack.getCluster() != null) {
HostMetadata hostMetadata = hostMetadataRepository.findHostInClusterByName(stack.getCluster().getId(), instanceMetaData.getDiscoveryFQDN());
if (hostMetadata != null) {
LOGGER.info("Remove obsolete host: {}", hostMetadata.getHostName());
stackScalingService.removeHostmetadataIfExists(stack, instanceMetaData, hostMetadata);
}
}
}
LOGGER.info("Terminate instance result: {}", payload);
stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.AVAILABLE, "Instance removed");
flowMessageService.fireEventAndLog(stack.getId(), Msg.STACK_REMOVING_INSTANCE_FINISHED, AVAILABLE.name());
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class CandidateUnhealthyInstancesSelectorTest method setupInstanceGroup.
private InstanceGroup setupInstanceGroup(InstanceGroupType instanceGroupType) {
InstanceGroup slaveGroup = mock(InstanceGroup.class);
when(slaveGroup.getInstanceGroupType()).thenReturn(instanceGroupType);
return slaveGroup;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class ClusterBootstrapperErrorHandler method terminateFailedNodes.
public void terminateFailedNodes(HostOrchestrator hostOrchestrator, ContainerOrchestrator containerOrchestrator, Stack stack, GatewayConfig gatewayConfig, Set<Node> nodes) throws CloudbreakOrchestratorFailedException {
List<String> allAvailableNode;
allAvailableNode = hostOrchestrator != null ? hostOrchestrator.getAvailableNodes(gatewayConfig, nodes) : containerOrchestrator.getAvailableNodes(gatewayConfig, nodes);
List<Node> missingNodes = selectMissingNodes(nodes, allAvailableNode);
if (!missingNodes.isEmpty()) {
String message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_BOOTSTRAP_FAILED_ON_NODES.code(), Collections.singletonList(missingNodes.size()));
LOGGER.info(message);
eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
for (Node missingNode : missingNodes) {
InstanceMetaData instanceMetaData = instanceMetaDataRepository.findNotTerminatedByPrivateAddress(stack.getId(), missingNode.getPrivateIp());
InstanceGroup ig = instanceGroupRepository.findOneByGroupNameInStack(stack.getId(), instanceMetaData.getInstanceGroup().getGroupName());
ig.setNodeCount(ig.getNodeCount() - 1);
if (ig.getNodeCount() < 1) {
throw new CloudbreakOrchestratorFailedException(cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_INVALID_NODECOUNT.code(), Collections.singletonList(ig.getGroupName())));
}
instanceGroupRepository.save(ig);
message = cloudbreakMessagesService.getMessage(Msg.BOOTSTRAPPER_ERROR_DELETING_NODE.code(), Arrays.asList(instanceMetaData.getInstanceId(), ig.getGroupName()));
LOGGER.info(message);
eventService.fireCloudbreakEvent(stack.getId(), Status.UPDATE_IN_PROGRESS.name(), message);
deleteResourceAndDependencies(stack, instanceMetaData);
deleteInstanceResourceFromDatabase(stack, instanceMetaData);
long timeInMillis = Calendar.getInstance().getTimeInMillis();
instanceMetaData.setTerminationDate(timeInMillis);
instanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
instanceMetaDataRepository.save(instanceMetaData);
LOGGER.info("InstanceMetadata [name: {}, id: {}] status set to {}.", instanceMetaData.getId(), instanceMetaData.getInstanceId(), instanceMetaData.getInstanceStatus());
}
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildInstanceGroups.
public List<Group> buildInstanceGroups(List<InstanceGroup> instanceGroups, StackAuthentication stackAuthentication, Collection<String> deleteRequests) {
// sort by name to avoid shuffling the different instance groups
Collections.sort(instanceGroups);
List<Group> groups = new ArrayList<>();
long privateId = getFirstValidPrivateId(instanceGroups);
for (InstanceGroup instanceGroup : instanceGroups) {
if (instanceGroup.getTemplate() != null) {
CloudInstance skeleton = null;
List<CloudInstance> instances = new ArrayList<>();
Template template = instanceGroup.getTemplate();
int desiredNodeCount = instanceGroup.getNodeCount();
// existing instances
for (InstanceMetaData metaData : instanceGroup.getInstanceMetaData()) {
InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
instances.add(buildInstance(metaData, template, stackAuthentication, instanceGroup.getGroupName(), metaData.getPrivateId(), status));
}
// new instances
int existingNodesSize = instances.size();
if (existingNodesSize < desiredNodeCount) {
for (long i = 0; i < desiredNodeCount - existingNodesSize; i++) {
instances.add(buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), privateId++, InstanceStatus.CREATE_REQUESTED));
}
}
if (existingNodesSize == desiredNodeCount && desiredNodeCount == 0) {
skeleton = buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), 0L, InstanceStatus.CREATE_REQUESTED);
}
Json attributes = instanceGroup.getAttributes();
InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
groups.add(new Group(instanceGroup.getGroupName(), instanceGroup.getInstanceGroupType(), instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
}
}
return groups;
}
use of com.sequenceiq.cloudbreak.domain.InstanceGroup in project cloudbreak by hortonworks.
the class StackRequestToStackConverter method convert.
@Override
public Stack convert(StackRequest source) {
Stack stack = new Stack();
stack.setName(source.getName());
stack.setDisplayName(source.getName());
stack.setRegion(getRegion(source));
setPlatform(source);
stack.setCloudPlatform(source.getCloudPlatform());
Map<String, String> sourceTags = source.getApplicationTags();
stack.setTags(getTags(mergeTags(sourceTags, source.getUserDefinedTags(), getDefaultTags(source))));
if (sourceTags != null && sourceTags.get("datalakeId") != null) {
stack.setDatalakeId(Long.valueOf(String.valueOf(sourceTags.get("datalakeId"))));
}
StackAuthentication stackAuthentication = conversionService.convert(source.getStackAuthentication(), StackAuthentication.class);
stack.setStackAuthentication(stackAuthentication);
validateStackAuthentication(source);
stack.setOwner(source.getOwner());
stack.setAvailabilityZone(source.getAvailabilityZone());
stack.setOnFailureActionAction(source.getOnFailureAction());
stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED.getStatus(), "", DetailedStackStatus.PROVISION_REQUESTED));
stack.setFailurePolicy(getConversionService().convert(source.getFailurePolicy(), FailurePolicy.class));
stack.setCreated(Calendar.getInstance().getTimeInMillis());
stack.setPlatformVariant(source.getPlatformVariant());
stack.setOrchestrator(getConversionService().convert(source.getOrchestrator(), Orchestrator.class));
if (source.getCredential() != null) {
stack.setCredential(getConversionService().convert(source.getCredential(), Credential.class));
}
Set<InstanceGroup> instanceGroups = convertInstanceGroups(source, stack);
stack.setInstanceGroups(instanceGroups);
if (source.getNetwork() != null) {
stack.setNetwork(getConversionService().convert(source.getNetwork(), Network.class));
}
stack.setCustomDomain(source.getCustomDomain());
stack.setCustomHostname(source.getCustomHostname());
stack.setClusterNameAsSubdomain(source.isClusterNameAsSubdomain());
stack.setHostgroupNameAsHostname(source.isHostgroupNameAsHostname());
stack.setUuid(UUID.randomUUID().toString());
return stack;
}
Aggregations