Search in sources :

Example 11 with CloudInstance

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

the class AzureTemplateBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    ReflectionTestUtils.setField(azureTemplateBuilder, "freemarkerConfiguration", configuration);
    ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplatePath", templatePath);
    ReflectionTestUtils.setField(azureTemplateBuilder, "armTemplateParametersPath", "templates/parameters.ftl");
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, CORE_CUSTOM_DATA, InstanceGroupType.GATEWAY, GATEWAY_CUSTOM_DATA);
    groups = new ArrayList<>();
    stackName = "testStack";
    name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
    Map<String, Object> params = new HashMap<>();
    params.put(CloudInstance.SUBNET_ID, "existingSubnet");
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication, params);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    security = new Security(rules, null);
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    cloudContext = new CloudContext(7899L, "thisisaverylongazureresourcenamewhichneedstobeshortened", "dummy1", "dummy2", "test", Location.location(Region.region("EU"), new AvailabilityZone("availabilityZone")));
    azureCredentialView = new AzureCredentialView(cloudCredential("siq-haas"));
    azureStorageView = new AzureStorageView(azureCredentialView, cloudContext, azureStorage, null);
    azureSubnetStrategy = AzureSubnetStrategy.getAzureSubnetStrategy(FILL, Collections.singletonList("existingSubnet"), ImmutableMap.of("existingSubnet", 100));
    defaultTags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
    defaultTags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
    defaultTags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
    defaultTags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
    defaultTags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
    defaultTags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
    defaultTags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
    reset(azureUtils);
}
Also used : InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) AzureStorageView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureStorageView) AzureCredentialView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Example 12 with CloudInstance

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

the class GcpAttachedDiskResourceBuilder method build.

@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
    CloudInstance instance = group.getReferenceInstanceConfiguration();
    InstanceTemplate template = instance.getTemplate();
    Volume volume = template.getVolumes().get(0);
    List<CloudResource> resources = new ArrayList<>();
    List<CloudResource> syncedResources = Collections.synchronizedList(resources);
    String projectId = context.getProjectId();
    Location location = context.getLocation();
    Compute compute = context.getCompute();
    Collection<Future<Void>> futures = new ArrayList<>();
    for (CloudResource cloudResource : buildableResource) {
        Disk disk = createDisk(volume, projectId, location.getAvailabilityZone(), cloudResource.getName(), tags);
        Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
            Insert insDisk = compute.disks().insert(projectId, location.getAvailabilityZone().value(), disk);
            try {
                Operation operation = insDisk.execute();
                syncedResources.add(createOperationAwareCloudResource(cloudResource, operation));
                if (operation.getHttpErrorStatusCode() != null) {
                    throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), cloudResource.getName());
                }
            } catch (GoogleJsonResponseException e) {
                throw new GcpResourceException(checkException(e), resourceType(), cloudResource.getName());
            }
            return null;
        });
        futures.add(submit);
    }
    for (Future<Void> future : futures) {
        future.get();
    }
    return resources;
}
Also used : ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Disks.Insert) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Compute(com.google.api.services.compute.Compute) Future(java.util.concurrent.Future) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.google.api.services.compute.model.Disk) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 13 with CloudInstance

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

the class GcpInstanceResourceBuilder method stopStart.

private CloudVmInstanceStatus stopStart(GcpContext context, AuthenticatedContext auth, CloudInstance instance, boolean stopRequest) {
    String projectId = GcpStackUtil.getProjectId(auth.getCloudCredential());
    String availabilityZone = context.getLocation().getAvailabilityZone().value();
    Compute compute = context.getCompute();
    String instanceId = instance.getInstanceId();
    try {
        Get get = compute.instances().get(projectId, availabilityZone, instanceId);
        String state = stopRequest ? "RUNNING" : "TERMINATED";
        if (state.equals(get.execute().getStatus())) {
            Operation operation = stopRequest ? compute.instances().stop(projectId, availabilityZone, instanceId).setPrettyPrint(true).execute() : compute.instances().start(projectId, availabilityZone, instanceId).setPrettyPrint(true).execute();
            CloudInstance operationAwareCloudInstance = createOperationAwareCloudInstance(instance, operation);
            return checkInstances(context, auth, Collections.singletonList(operationAwareCloudInstance)).get(0);
        } else {
            LOGGER.info("Instance {} is not in {} state - won't start it.", state, instanceId);
            return null;
        }
    } catch (IOException e) {
        throw new GcpResourceException(String.format("An error occurred while stopping the vm '%s'", instanceId), e);
    }
}
Also used : Compute(com.google.api.services.compute.Compute) Get(com.google.api.services.compute.Compute.Instances.Get) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException)

Example 14 with CloudInstance

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

the class GcpInstanceResourceBuilderTest method newGroupWithParams.

public Group newGroupWithParams(Map<String, Object> params) {
    InstanceTemplate instanceTemplate = new InstanceTemplate(flavor, name, privateId, volumes, InstanceStatus.CREATE_REQUESTED, params, 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance cloudInstance = new CloudInstance(instanceId, instanceTemplate, instanceAuthentication);
    return new Group(name, InstanceGroupType.CORE, Collections.singletonList(cloudInstance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 15 with CloudInstance

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

the class GcpMetadataCollector method getCloudVmMetaDataStatus.

private CloudVmMetaDataStatus getCloudVmMetaDataStatus(AuthenticatedContext authenticatedContext, CloudResource cloudResource, CloudInstance matchedInstance) {
    CloudVmMetaDataStatus cloudVmMetaDataStatus;
    if (cloudResource != null) {
        CloudInstance cloudInstance = new CloudInstance(cloudResource.getName(), matchedInstance.getTemplate(), matchedInstance.getAuthentication());
        try {
            CloudCredential credential = authenticatedContext.getCloudCredential();
            CloudContext cloudContext = authenticatedContext.getCloudContext();
            Compute compute = GcpStackUtil.buildCompute(credential);
            Instance executeInstance = getInstance(cloudContext, credential, compute, cloudResource.getName());
            String privateIp = executeInstance.getNetworkInterfaces().get(0).getNetworkIP();
            String publicIp = null;
            List<AccessConfig> acl = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs();
            if (acl != null && acl.get(0) != null) {
                publicIp = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP();
            }
            CloudInstanceMetaData metaData = new CloudInstanceMetaData(privateIp, publicIp);
            CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
            cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, metaData);
        } catch (IOException e) {
            LOGGER.warn(String.format("Instance %s is not reachable", cloudResource.getName()), e);
            CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.UNKNOWN);
            cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
        }
    } else {
        CloudVmInstanceStatus status = new CloudVmInstanceStatus(matchedInstance, InstanceStatus.TERMINATED);
        cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
    }
    return cloudVmMetaDataStatus;
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Instance(com.google.api.services.compute.model.Instance) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Compute(com.google.api.services.compute.Compute) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) IOException(java.io.IOException) AccessConfig(com.google.api.services.compute.model.AccessConfig)

Aggregations

CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)75 ArrayList (java.util.ArrayList)41 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)32 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)25 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)20 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)17 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)16 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)14 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)12 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)10 Group (com.sequenceiq.cloudbreak.cloud.model.Group)10 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)10 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)9 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)7 Instance (com.amazonaws.services.ec2.model.Instance)7