Search in sources :

Example 76 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class MetadataSetupService method saveInstanceMetaData.

public int saveInstanceMetaData(Stack stack, Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatusList, InstanceStatus status) {
    int newInstances = 0;
    Set<InstanceMetaData> allInstanceMetadata = instanceMetaDataService.findNotTerminatedForStack(stack.getId());
    boolean primaryIgSelected = allInstanceMetadata.stream().anyMatch(imd -> imd.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY);
    for (CloudVmMetaDataStatus cloudVmMetaDataStatus : cloudVmMetaDataStatusList) {
        CloudInstance cloudInstance = cloudVmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance();
        CloudInstanceMetaData md = cloudVmMetaDataStatus.getMetaData();
        Long privateId = cloudInstance.getTemplate().getPrivateId();
        String instanceId = cloudInstance.getInstanceId();
        InstanceMetaData instanceMetaDataEntry = createInstanceMetadataIfAbsent(allInstanceMetadata, privateId, instanceId);
        if (instanceMetaDataEntry.getInstanceId() == null) {
            newInstances++;
        }
        // CB 1.0.x clusters do not have private id thus we cannot correlate them with instance groups thus keep the original one
        InstanceGroup ig = instanceMetaDataEntry.getInstanceGroup();
        String group = ig == null ? cloudInstance.getTemplate().getGroupName() : ig.getGroupName();
        InstanceGroup instanceGroup = instanceGroupService.findOneByGroupNameInStack(stack.getId(), group).orElse(null);
        instanceMetaDataEntry.setPrivateIp(md.getPrivateIp());
        instanceMetaDataEntry.setPublicIp(md.getPublicIp());
        instanceMetaDataEntry.setSshPort(md.getSshPort());
        instanceMetaDataEntry.setLocalityIndicator(md.getLocalityIndicator());
        instanceMetaDataEntry.setInstanceGroup(instanceGroup);
        instanceMetaDataEntry.setInstanceId(instanceId);
        instanceMetaDataEntry.setPrivateId(privateId);
        instanceMetaDataEntry.setStartDate(clock.getCurrentTimeMillis());
        instanceMetaDataEntry.setSubnetId(cloudInstance.getSubnetId());
        instanceMetaDataEntry.setAvailabilityZone(cloudInstance.getAvailabilityZone());
        instanceMetaDataEntry.setInstanceName(cloudInstance.getStringParameter(CloudInstance.INSTANCE_NAME));
        instanceMetaDataEntry.setLifeCycle(convertLifeCycle(md));
        if (instanceMetaDataEntry.getInstanceMetadataType() == null) {
            if (ig != null) {
                if (!primaryIgSelected && ig.getInstanceGroupType() == com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupType.MASTER) {
                    primaryIgSelected = true;
                    instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY_PRIMARY);
                } else {
                    instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
                }
            } else {
                instanceMetaDataEntry.setInstanceMetadataType(InstanceMetadataType.GATEWAY);
            }
        }
        if (status != null) {
            instanceMetaDataEntry.setInstanceStatus(status);
        }
        instanceMetaDataService.save(instanceMetaDataEntry);
    }
    return newInstances;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.freeipa.entity.InstanceGroup)

Example 77 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class FreeIpaStackHealthDetailsService method getHealthDetails.

public HealthDetailsFreeIpaResponse getHealthDetails(String environmentCrn, String accountId) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(environmentCrn, accountId);
    List<InstanceMetaData> instances = stack.getAllInstanceMetaDataList();
    HealthDetailsFreeIpaResponse response = new HealthDetailsFreeIpaResponse();
    for (InstanceMetaData instance : instances) {
        if (shouldRunHealthCheck(instance)) {
            try {
                NodeHealthDetails nodeHealthDetails = freeIpaInstanceHealthDetailsService.getInstanceHealthDetails(stack, instance);
                response.addNodeHealthDetailsFreeIpaResponses(nodeHealthDetails);
            } catch (Exception e) {
                addUnreachableResponse(instance, response, e.getLocalizedMessage());
                LOGGER.error(String.format("Unable to check the health of FreeIPA instance: %s", instance.getInstanceId()), e);
            }
        } else {
            NodeHealthDetails nodeResponse = new NodeHealthDetails();
            response.addNodeHealthDetailsFreeIpaResponses(nodeResponse);
            nodeResponse.setName(instance.getDiscoveryFQDN());
            nodeResponse.setStatus(instance.getInstanceStatus());
            nodeResponse.setInstanceId(instance.getInstanceId());
            nodeResponse.addIssue("Unable to check health as instance is " + instance.getInstanceStatus().name());
        }
    }
    return updateResponse(stack, response);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) HealthDetailsFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 78 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class HostMetadataSetup method updateWithHostData.

private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) throws CloudbreakOrchestratorException {
    List<String> privateIps = metadataToUpdate.stream().map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
    GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
    Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
    LOGGER.debug("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
    for (InstanceMetaData instanceMetaData : metadataToUpdate) {
        String address = members.get(instanceMetaData.getPrivateIp());
        instanceMetaData.setDiscoveryFQDN(address);
        LOGGER.debug("Domain used for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), address, instanceMetaData.getDiscoveryFQDN());
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 79 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class RepairInstancesService method rebootInstances.

/**
 * If no instance passed in request, reboot all bad instances
 * If instances passed in request, reboot all valid passed bad instances
 * If force and instances passed in request, reboot all valid passed instances
 * If force and no instances passed in request, reboot all instances
 *
 * @param accountId - The account id for the instance to reboot.
 * @param request   - A RebootInstanceRequest containing request parameters.
 */
public OperationStatus rebootInstances(String accountId, RebootInstancesRequest request) {
    Stack stack = stackService.getByEnvironmentCrnAndAccountIdWithListsAndMdcContext(request.getEnvironmentCrn(), accountId);
    Map<String, InstanceMetaData> allInstancesByInstanceId = getAllInstancesFromStack(stack);
    Map<String, InstanceStatus> healthMap = request.isForceReboot() ? Collections.emptyMap() : getInstanceHealthMap(accountId, request.getEnvironmentCrn());
    Map<String, InstanceMetaData> instancesToReboot = getInstancesToRepair(healthMap, allInstancesByInstanceId, request.getInstanceIds(), request.isForceReboot(), true);
    if (instancesToReboot.keySet().isEmpty()) {
        throw new NotFoundException("No unhealthy instances to reboot.  Maybe use the force option.");
    }
    Operation operation = operationService.startOperation(accountId, OperationType.REBOOT, Set.of(stack.getEnvironmentCrn()), Collections.emptySet());
    if (operation.getStatus() == OperationState.RUNNING) {
        stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_REQUESTED, "Reboot requested");
        flowManager.notify(REBOOT_EVENT.event(), new RebootInstanceEvent(REBOOT_EVENT.event(), stack.getId(), instancesToReboot.keySet().stream().collect(Collectors.toList()), operation.getOperationId()));
    }
    return operationToOperationStatusConverter.convert(operation);
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) RebootInstanceEvent(com.sequenceiq.freeipa.flow.instance.reboot.RebootInstanceEvent) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Operation(com.sequenceiq.freeipa.entity.Operation) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 80 with InstanceMetaData

use of com.sequenceiq.freeipa.entity.InstanceMetaData in project cloudbreak by hortonworks.

the class ProviderChecker method updateAndGetStatuses.

public List<ProviderSyncResult> updateAndGetStatuses(Stack stack, Set<InstanceMetaData> checkableInstances, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap, boolean updateStatusFromFlow) {
    return checkedMeasure(() -> {
        List<ProviderSyncResult> results = new ArrayList<>();
        List<CloudVmInstanceStatus> statuses = stackInstanceProviderChecker.checkStatus(stack, checkableInstances);
        if (!updateStatusFromFlow && flowLogService.isOtherFlowRunning(stack.getId())) {
            throw new InterruptSyncingException(":::Auto sync::: interrupt syncing in updateAndGetStatuses, flow is running on freeipa stack " + stack.getName());
        } else {
            statuses.forEach(s -> {
                Optional<InstanceMetaData> instanceMetaData = checkableInstances.stream().filter(i -> s.getCloudInstance().getInstanceId().equals(i.getInstanceId())).findFirst();
                if (instanceMetaData.isPresent()) {
                    InstanceStatus instanceStatus = updateStatuses(s, instanceMetaData.get(), instanceHealthStatusMap);
                    if (instanceStatus != null) {
                        results.add(new ProviderSyncResult("", instanceStatus, false, s.getCloudInstance().getInstanceId()));
                    }
                } else {
                    LOGGER.info(":::Auto sync::: Cannot find instanceMetaData");
                }
            });
            checkableInstances.forEach(instanceMetaData -> {
                if (statuses.stream().noneMatch(s -> s.getCloudInstance().getInstanceId().equals(instanceMetaData.getInstanceId()))) {
                    if (updateStatus) {
                        setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE);
                        instanceMetaDataService.save(instanceMetaData);
                    } else {
                        LOGGER.debug("updateStatus flag is false, don't update status");
                    }
                }
            });
            return results;
        }
    }, LOGGER, ":::Auto sync::: provider is checked in {}ms");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Benchmark.checkedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.checkedMeasure) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) Set(java.util.Set) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) Optional(java.util.Optional) FlowLogService(com.sequenceiq.flow.core.FlowLogService) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList)

Aggregations

InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)163 Stack (com.sequenceiq.freeipa.entity.Stack)104 Test (org.junit.jupiter.api.Test)77 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)30 List (java.util.List)19 Logger (org.slf4j.Logger)19 LoggerFactory (org.slf4j.LoggerFactory)19 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Inject (javax.inject.Inject)18 Set (java.util.Set)16 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)13 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)13 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)12 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)11 StackService (com.sequenceiq.freeipa.service.stack.StackService)10 ArrayList (java.util.ArrayList)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 HealthDetailsFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.HealthDetailsFreeIpaResponse)9 Operation (com.sequenceiq.freeipa.entity.Operation)9