Search in sources :

Example 11 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClouderaManagerDecomissioner method collectHostsToRemove.

public Map<String, InstanceMetaData> collectHostsToRemove(Stack stack, HostGroup hostGroup, Set<String> hostNames, ApiClient client) {
    Set<InstanceMetaData> hostsInHostGroup = hostGroup.getInstanceGroup().getNotTerminatedInstanceMetaDataSet();
    Map<String, InstanceMetaData> hostsToRemove = hostsInHostGroup.stream().filter(hostMetadata -> hostNames.contains(hostMetadata.getDiscoveryFQDN())).collect(Collectors.toMap(InstanceMetaData::getDiscoveryFQDN, hostMetadata -> hostMetadata));
    if (hostsToRemove.size() != hostNames.size()) {
        List<String> missingHosts = hostNames.stream().filter(h -> !hostsToRemove.containsKey(h)).collect(Collectors.toList());
        LOGGER.debug("Not all requested hosts found in CB for host group: {}. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", hostGroup.getName(), missingHosts.size(), missingHosts, hostNames);
    }
    HostsResourceApi hostsResourceApi = clouderaManagerApiFactory.getHostsResourceApi(client);
    try {
        ApiHostList hostRefList = hostsResourceApi.readHosts(null, null, SUMMARY_REQUEST_VIEW);
        List<String> runningHosts = hostRefList.getItems().stream().map(ApiHost::getHostname).collect(Collectors.toList());
        // TODO: what if i remove a node from CM manually?
        List<String> matchingCmHosts = hostsToRemove.keySet().stream().filter(hostName -> runningHosts.contains(hostName)).collect(Collectors.toList());
        Set<String> matchingCmHostSet = new HashSet<>(matchingCmHosts);
        if (matchingCmHosts.size() != hostsToRemove.size()) {
            List<String> missingHostsInCm = hostsToRemove.keySet().stream().filter(h -> !matchingCmHostSet.contains(h)).collect(Collectors.toList());
            LOGGER.debug("Not all requested hosts found in CM. MissingCount={}, missingHosts=[{}]. Requested hosts: [{}]", missingHostsInCm.size(), missingHostsInCm, hostsToRemove.keySet());
        }
        Sets.newHashSet(hostsToRemove.keySet()).stream().filter(hostName -> !matchingCmHostSet.contains(hostName)).forEach(hostsToRemove::remove);
        LOGGER.debug("Collected hosts to remove: [{}]", hostsToRemove);
        return hostsToRemove;
    } catch (ApiException e) {
        LOGGER.error("Failed to get host list for cluster: {}", stack.getName(), e);
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) ApiException(com.cloudera.api.swagger.client.ApiException) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) FlowMessageService(com.sequenceiq.cloudbreak.message.FlowMessageService) Map(java.util.Map) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiHostsToRemoveArgs(com.cloudera.api.swagger.model.ApiHostsToRemoveArgs) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ApiHostNameList(com.cloudera.api.swagger.model.ApiHostNameList) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) HostServiceStatuses(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatuses) HostServiceStatus(com.sequenceiq.cloudbreak.cluster.status.HostServiceStatus) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) Function(java.util.function.Function) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ApiHost(com.cloudera.api.swagger.model.ApiHost) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) Logger(org.slf4j.Logger) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Consumer(java.util.function.Consumer) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Component(org.springframework.stereotype.Component) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CommandsResourceApi(com.cloudera.api.swagger.CommandsResourceApi) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) MgmtServiceResourceApi(com.cloudera.api.swagger.MgmtServiceResourceApi) Comparator(java.util.Comparator) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) StringUtils(org.springframework.util.StringUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) HashSet(java.util.HashSet) ApiException(com.cloudera.api.swagger.client.ApiException)

Example 12 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class NetworkV1ToNetworkV4Converter method convertToAwsStackRequest.

private AwsNetworkV4Parameters convertToAwsStackRequest(Pair<AwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
    EnvironmentNetworkResponse value = source.getValue();
    AwsNetworkV1Parameters key = source.getKey();
    AwsNetworkV4Parameters response = new AwsNetworkV4Parameters();
    if (key != null) {
        response.setVpcId(value.getAws().getVpcId());
        String subnetId = key.getSubnetId();
        if (!Strings.isNullOrEmpty(subnetId)) {
            response.setSubnetId(key.getSubnetId());
        } else if (value != null) {
            response.setSubnetId(value.getPreferedSubnetId());
        }
        if (PublicEndpointAccessGateway.ENABLED.equals(value.getPublicEndpointAccessGateway())) {
            ValidationResult validationResult = endpointGatewayNetworkValidator.validate(new ImmutablePair<>(response.getSubnetId(), value));
            if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
                throw new BadRequestException("Endpoint gateway subnet validation failed: " + validationResult.getFormattedErrors());
            }
            Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(value, response.getSubnetId());
            if (endpointGatewaySubnet.isPresent()) {
                response.setEndpointGatewaySubnetId(endpointGatewaySubnet.get().getId());
            }
        }
    }
    return response;
}
Also used : EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AwsNetworkV1Parameters(com.sequenceiq.distrox.api.v1.distrox.model.network.aws.AwsNetworkV1Parameters) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AwsNetworkV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.network.AwsNetworkV4Parameters)

Example 13 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class BlueprintV4RequestToBlueprintConverterTest method rejectsBuiltinWithoutContent.

@Test
public void rejectsBuiltinWithoutContent() {
    BlueprintV4Request request = new BlueprintV4Request();
    request.setBlueprint("{ \"blueprint\": {}");
    thrown.expect(BadRequestException.class);
    thrown.expectMessage("Invalid cluster template: Failed to parse JSON.");
    underTest.convert(request);
}
Also used : BlueprintV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.blueprint.requests.BlueprintV4Request) Test(org.junit.Test) AbstractJsonConverterTest(com.sequenceiq.cloudbreak.converter.AbstractJsonConverterTest)

Example 14 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClusterUpgradeAvailabilityServiceTest method testGetImagesToUpgradeShouldReturnEmptyListWhenCurrentImageIsNotFound.

@Test
public void testGetImagesToUpgradeShouldReturnEmptyListWhenCurrentImageIsNotFound() throws CloudbreakImageNotFoundException {
    Stack stack = createStack(createStackStatus(Status.AVAILABLE), DATALAKE_STACK_TYPE);
    when(imageService.getImage(stack.getId())).thenThrow(new CloudbreakImageNotFoundException("Image not found."));
    UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
    assertNull(actual.getCurrent());
    assertNull(actual.getUpgradeCandidates());
    assertEquals("Failed to retrieve image due to Image not found.", actual.getReason());
}
Also used : UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Example 15 with FAILED

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED in project cloudbreak by hortonworks.

the class ClusterTemplateTest method validateDefaultCount.

private ClusterTemplateTestDto validateDefaultCount(TestContext tc, ClusterTemplateTestDto entity, CloudbreakClient cc) {
    try {
        assertNotNull(entity);
        assertNotNull(entity.getResponses());
        long defaultCount = entity.getResponses().stream().filter(template -> ResourceStatus.DEFAULT.equals(template.getStatus())).count();
        long expectedCount = 602;
        assertEquals("Should have " + expectedCount + " of default cluster templates.", expectedCount, defaultCount);
    } catch (Exception e) {
        throw new TestFailException(String.format("Failed to validate default count of cluster templates: %s", e.getMessage()), e);
    }
    return entity;
}
Also used : ClusterTestDto(com.sequenceiq.it.cloudbreak.dto.ClusterTestDto) DistroXTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.clustertemplate.DistroXTemplateTestDto) ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) DistroXImageTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.image.DistroXImageTestDto) ClusterTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.clustertemplate.ClusterTemplateTestDto) Test(org.testng.annotations.Test) StringUtils(org.apache.commons.lang3.StringUtils) MockCloudProvider(com.sequenceiq.it.cloudbreak.cloud.v4.mock.MockCloudProvider) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) DistroXNetworkTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.instancegroup.DistroXNetworkTestDto) StackTemplateTestDto(com.sequenceiq.it.cloudbreak.dto.stack.StackTemplateTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BadRequestException(javax.ws.rs.BadRequestException) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) ClusterTemplateAuditGrpcServiceAssertion(com.sequenceiq.it.cloudbreak.assertion.audit.ClusterTemplateAuditGrpcServiceAssertion) Assert.assertNotNull(org.junit.Assert.assertNotNull) PlacementSettingsTestDto(com.sequenceiq.it.cloudbreak.dto.PlacementSettingsTestDto) DistroXClouderaManagerTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.cluster.clouderamanager.DistroXClouderaManagerTestDto) ClusterTemplateV4Type(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.ClusterTemplateV4Type) LdapTestClient(com.sequenceiq.it.cloudbreak.client.LdapTestClient) ClusterTemplateTestAssertion(com.sequenceiq.it.cloudbreak.assertion.clustertemplate.ClusterTemplateTestAssertion) NotFoundException(javax.ws.rs.NotFoundException) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) ClusterTemplateTestClient(com.sequenceiq.it.cloudbreak.client.ClusterTemplateTestClient) EnvironmentTestClient(com.sequenceiq.it.cloudbreak.client.EnvironmentTestClient) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) RunningParameter(com.sequenceiq.it.cloudbreak.context.RunningParameter) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) RecipeTestClient(com.sequenceiq.it.cloudbreak.client.RecipeTestClient) RunningParameter.expectedMessage(com.sequenceiq.it.cloudbreak.context.RunningParameter.expectedMessage) Assert.assertEquals(org.junit.Assert.assertEquals) ImageCatalogTestDto(com.sequenceiq.it.cloudbreak.dto.imagecatalog.ImageCatalogTestDto) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 List (java.util.List)19 Set (java.util.Set)18 Inject (javax.inject.Inject)18 Optional (java.util.Optional)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Map (java.util.Map)16 Collectors (java.util.stream.Collectors)15 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)14 HashSet (java.util.HashSet)13 Status (com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status)11 Collection (java.util.Collection)11 Collections (java.util.Collections)11 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)9 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)9 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)8 VolumeSetAttributes (com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)8 ResourceAttributeUtil (com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil)8 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8