Search in sources :

Example 6 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method launch.

@SuppressWarnings("unchecked")
@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier notifier, AdjustmentType adjustmentType, Long threshold) {
    String stackName = utils.getStackName(authenticatedContext);
    NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
    boolean existingNetwork = neutronNetworkView.isExistingNetwork();
    String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
    ModelContext modelContext = new ModelContext();
    modelContext.withExistingNetwork(existingNetwork);
    modelContext.withExistingSubnet(existingSubnetCidr != null);
    modelContext.withGroups(stack.getGroups());
    modelContext.withInstanceUserData(stack.getImage());
    modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
    modelContext.withStackName(stackName);
    modelContext.withNeutronNetworkView(neutronNetworkView);
    modelContext.withTemplateString(stack.getTemplate());
    modelContext.withTags(stack.getTags());
    String heatTemplate = heatTemplateBuilder.build(modelContext);
    Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
    OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
    List<CloudResourceStatus> resources;
    Stack existingStack = client.heat().stacks().getStackByName(stackName);
    if (existingStack == null) {
        if (stack.getInstanceAuthentication().getPublicKeyId() == null) {
            createKeyPair(authenticatedContext, stack, client);
        }
        Stack heatStack = client.heat().stacks().create(Builders.stack().name(stackName).template(heatTemplate).disableRollback(false).parameters(parameters).timeoutMins(OPERATION_TIMEOUT).build());
        List<CloudResource> cloudResources = collectResources(authenticatedContext, notifier, heatStack, stack, neutronNetworkView);
        resources = check(authenticatedContext, cloudResources);
    } else {
        LOGGER.info("Heat stack already exists: {}", existingStack.getName());
        CloudResource cloudResource = new Builder().type(ResourceType.HEAT_STACK).name(existingStack.getId()).build();
        resources = Collections.singletonList(new CloudResourceStatus(cloudResource, ResourceStatus.CREATED));
    }
    LOGGER.debug("Launched resources: {}", resources);
    return resources;
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) Stack(org.openstack4j.model.heat.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 7 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method checkByResourceType.

private CloudResourceStatus checkByResourceType(AuthenticatedContext authenticatedContext, OSClient<?> client, String stackName, Collection<CloudResource> list, CloudResource resource) {
    CloudResourceStatus result = null;
    switch(resource.getType()) {
        case HEAT_STACK:
            String heatStackId = resource.getName();
            LOGGER.info("Checking OpenStack Heat stack status of: {}", stackName);
            Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
            result = utils.heatStatus(resource, heatStack);
            break;
        case OPENSTACK_NETWORK:
            result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_NETWORK);
            break;
        case OPENSTACK_SUBNET:
            result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_SUBNET);
            break;
        case OPENSTACK_ROUTER:
        case OPENSTACK_INSTANCE:
        case OPENSTACK_PORT:
        case OPENSTACK_ATTACHED_DISK:
        case OPENSTACK_SECURITY_GROUP:
        case OPENSTACK_FLOATING_IP:
            break;
        default:
            throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
    }
    return result;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Stack(org.openstack4j.model.heat.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 8 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class AbstractOpenStackResourceBuilder method checkResources.

protected List<CloudResourceStatus> checkResources(ResourceType type, OpenStackContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        LOGGER.info("Check {} resource: {}", type, resource);
        try {
            boolean finished = checkStatus(context, auth, resource);
            ResourceStatus successStatus = context.isBuild() ? ResourceStatus.CREATED : ResourceStatus.DELETED;
            result.add(new CloudResourceStatus(resource, finished ? successStatus : ResourceStatus.IN_PROGRESS));
            if (finished) {
                if (successStatus == ResourceStatus.CREATED) {
                    LOGGER.info("Creation of {} was successful", resource);
                } else {
                    LOGGER.info("Deletion of {} was successful", resource);
                }
            }
        } catch (OS4JException ex) {
            throw new OpenStackResourceException("Error during status check", type, resource.getName(), ex);
        }
    }
    return result;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 9 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class MockResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) {
    List<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>();
    for (Group group : stack.getGroups()) {
        for (int i = 0; i < group.getInstancesSize(); i++) {
            CloudResource cloudResource = new Builder().type(ResourceType.MOCK_INSTANCE).status(CommonStatus.CREATED).name("cloudinstance" + cloudResourceStatuses.size()).reference("").persistent(true).build();
            cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, CREATED));
        }
    }
    return cloudResourceStatuses;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 10 with CloudResourceStatus

use of com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus in project cloudbreak by hortonworks.

the class StackUpscaleService method transformResults.

private Set<Resource> transformResults(Iterable<CloudResourceStatus> cloudResourceStatuses, Stack stack) {
    Set<Resource> retSet = new HashSet<>();
    for (CloudResourceStatus cloudResourceStatus : cloudResourceStatuses) {
        if (!cloudResourceStatus.isFailed()) {
            CloudResource cloudResource = cloudResourceStatus.getCloudResource();
            Resource resource = new Resource(cloudResource.getType(), cloudResource.getName(), cloudResource.getReference(), cloudResource.getStatus(), stack, null);
            retSet.add(resource);
        }
    }
    return retSet;
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) HashSet(java.util.HashSet)

Aggregations

CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)43 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)29 ArrayList (java.util.ArrayList)18 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 List (java.util.List)11 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)5 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)5 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 NetworkResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.NetworkResourceBuilder)4 CloudException (com.microsoft.azure.CloudException)3 Deployment (com.microsoft.azure.management.resources.Deployment)3 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)3 ComputeResourceBuilder (com.sequenceiq.cloudbreak.cloud.template.ComputeResourceBuilder)3 ResourceBuilderContext (com.sequenceiq.cloudbreak.cloud.template.context.ResourceBuilderContext)3