Search in sources :

Example 21 with InstanceMetaData

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;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData)

Example 22 with InstanceMetaData

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());
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) Node(com.sequenceiq.cloudbreak.orchestrator.model.Node) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 23 with InstanceMetaData

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);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) HostOrchestratorClusterContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostBootstrapApiContext(com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 24 with InstanceMetaData

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;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.domain.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)

Example 25 with InstanceMetaData

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);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)71 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)24 Stack (com.sequenceiq.cloudbreak.domain.Stack)23 ArrayList (java.util.ArrayList)18 HashSet (java.util.HashSet)17 Map (java.util.Map)16 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)14 Test (org.junit.Test)14 HashMap (java.util.HashMap)13 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)11 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)9 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)9 List (java.util.List)9 Set (java.util.Set)9 Inject (javax.inject.Inject)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Matchers.anyString (org.mockito.Matchers.anyString)7