use of com.sequenceiq.cloudbreak.domain.InstanceMetaData in project cloudbreak by hortonworks.
the class UnhealthyInstancesFinalizerTest method setupInstanceMetaData.
private InstanceMetaData setupInstanceMetaData(String instanceId, Set<InstanceMetaData> candidateUnhealthyInstances) {
InstanceMetaData imd1 = mock(InstanceMetaData.class);
when(imd1.getInstanceId()).thenReturn(instanceId);
candidateUnhealthyInstances.add(imd1);
return imd1;
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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.InstanceMetaData in project cloudbreak by hortonworks.
the class ClusterBootstrapper method bootstrapNewNodesOnHost.
private void bootstrapNewNodesOnHost(Stack stack, List<GatewayConfig> allGatewayConfigs, Set<Node> nodes, Set<Node> allNodes) throws CloudbreakException, CloudbreakOrchestratorException {
HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
Cluster cluster = stack.getCluster();
Boolean enableKnox = cluster.getGateway().getEnableGateway();
for (InstanceMetaData gateway : stack.getGatewayInstanceMetadata()) {
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gateway, enableKnox);
PollingResult bootstrapApiPolling = hostBootstrapApiPollingService.pollWithTimeoutSingleFailure(hostBootstrapApiCheckerTask, new HostBootstrapApiContext(stack, gatewayConfig, hostOrchestrator), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
validatePollingResultForCancellation(bootstrapApiPolling, "Polling of bootstrap API was cancelled.");
}
byte[] stateZip = null;
ClusterComponent stateComponent = clusterComponentProvider.getComponent(cluster.getId(), ComponentType.SALT_STATE);
if (stateComponent != null) {
String content = (String) stateComponent.getAttributes().getMap().getOrDefault(ComponentType.SALT_STATE.name(), "");
if (!content.isEmpty()) {
stateZip = Base64.decodeBase64(content);
}
}
hostOrchestrator.bootstrapNewNodes(allGatewayConfigs, nodes, allNodes, stateZip, clusterDeletionBasedModel(stack.getId(), null));
InstanceMetaData primaryGateway = stack.getPrimaryGatewayInstance();
GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, primaryGateway, enableKnox);
PollingResult allNodesAvailabilityPolling = hostClusterAvailabilityPollingService.pollWithTimeoutSingleFailure(hostClusterAvailabilityCheckerTask, new HostOrchestratorClusterContext(stack, hostOrchestrator, gatewayConfig, nodes), POLL_INTERVAL, MAX_POLLING_ATTEMPTS);
validatePollingResultForCancellation(allNodesAvailabilityPolling, "Polling of new nodes availability was cancelled.");
if (TIMEOUT.equals(allNodesAvailabilityPolling)) {
clusterBootstrapperErrorHandler.terminateFailedNodes(hostOrchestrator, null, stack, gatewayConfig, nodes);
}
}
use of com.sequenceiq.cloudbreak.domain.InstanceMetaData 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.InstanceMetaData in project cloudbreak by hortonworks.
the class InstanceMetadataService method saveInstanceRequests.
public void saveInstanceRequests(Stack stack, Iterable<Group> groups) {
Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
for (Group group : groups) {
InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
List<InstanceMetaData> existingInGroup = instanceMetaDataRepository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
for (CloudInstance cloudInstance : group.getInstances()) {
InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
if (InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
InstanceMetaData instanceMetaData = new InstanceMetaData();
instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
instanceMetaData.setInstanceGroup(instanceGroup);
instanceMetaDataRepository.save(instanceMetaData);
}
}
}
}
Aggregations