Search in sources :

Example 1 with Image

use of org.jclouds.compute.domain.Image in project camel by apache.

the class JcloudsSpringComputeTest method testListImages.

@Test
public void testListImages() throws InterruptedException {
    result.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", null, JcloudsConstants.OPERATION, JcloudsConstants.LIST_IMAGES);
    result.assertIsSatisfied();
    List<Exchange> exchanges = result.getExchanges();
    if (exchanges != null && !exchanges.isEmpty()) {
        for (Exchange exchange : exchanges) {
            Set<?> images = exchange.getIn().getBody(Set.class);
            assertTrue(images.size() > 0);
            for (Object obj : images) {
                assertTrue(obj instanceof Image);
            }
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) Image(org.jclouds.compute.domain.Image) Test(org.junit.Test)

Example 2 with Image

use of org.jclouds.compute.domain.Image in project wildfly-camel by wildfly-extras.

the class JCloudsComputeIntegrationTest method testListImages.

@Test
public void testListImages() throws Exception {
    CamelContext camelctx = getCamelContext();
    ProducerTemplate template = camelctx.createProducerTemplate();
    MockEndpoint result = camelctx.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(1);
    template.sendBodyAndHeader("direct:start", null, JcloudsConstants.OPERATION, JcloudsConstants.LIST_IMAGES);
    result.assertIsSatisfied();
    List<Exchange> exchanges = result.getExchanges();
    if (exchanges != null && !exchanges.isEmpty()) {
        for (Exchange exchange : exchanges) {
            Set<?> images = exchange.getIn().getBody(Set.class);
            Assert.assertTrue(images.size() > 0);
            for (Object obj : images) {
                Assert.assertTrue(obj instanceof Image);
            }
        }
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Image(org.jclouds.compute.domain.Image) Test(org.junit.Test)

Example 3 with Image

use of org.jclouds.compute.domain.Image in project whirr by apache.

the class BootstrapTemplateTest method assertSpotPriceIs.

@SuppressWarnings("unchecked")
private void assertSpotPriceIs(ClusterSpec clusterSpec, final String templateGroup, float spotPrice) throws MalformedURLException {
    InstanceTemplate instanceTemplate = getOnlyElement(filter(clusterSpec.getInstanceTemplates(), new Predicate<InstanceTemplate>() {

        private Joiner plusJoiner = Joiner.on("+");

        @Override
        public boolean apply(InstanceTemplate group) {
            return plusJoiner.join(group.getRoles()).equals(templateGroup);
        }
    }));
    ComputeService computeService = mock(AWSEC2ComputeService.class);
    ComputeServiceContext context = mock(ComputeServiceContext.class);
    when(computeService.getContext()).thenReturn(context);
    when(context.getComputeService()).thenReturn(computeService);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    Template template = mock(Template.class);
    TemplateOptions options = mock(TemplateOptions.class);
    Image image = mock(Image.class);
    when(templateBuilder.build()).thenReturn(template);
    when(template.getOptions()).thenReturn(options);
    when(template.getImage()).thenReturn(image);
    AWSEC2TemplateOptions awsEec2TemplateOptions = mock(AWSEC2TemplateOptions.class);
    when(options.as((Class<TemplateOptions>) any())).thenReturn(awsEec2TemplateOptions);
    BootstrapTemplate.build(clusterSpec, computeService, statementBuilder, instanceTemplate);
    verify(awsEec2TemplateOptions).spotPrice(spotPrice);
}
Also used : Joiner(com.google.common.base.Joiner) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) TemplateOptions(org.jclouds.compute.options.TemplateOptions) AWSEC2TemplateOptions(org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions) Image(org.jclouds.compute.domain.Image) AWSEC2TemplateOptions(org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions) AWSEC2ComputeService(org.jclouds.aws.ec2.compute.AWSEC2ComputeService) ComputeService(org.jclouds.compute.ComputeService) InstanceTemplate(org.apache.whirr.InstanceTemplate) Predicate(com.google.common.base.Predicate) InstanceTemplate(org.apache.whirr.InstanceTemplate) Template(org.jclouds.compute.domain.Template)

Example 4 with Image

use of org.jclouds.compute.domain.Image in project legacy-jclouds-examples by jclouds.

the class CreateServer method getImage.

/**
 * This method uses the generic ComputeService.listImages() to find the image.
 *
 * @return An Ubuntu 12.04 Image
 */
private Image getImage() {
    System.out.println("Images");
    Set<? extends Image> images = compute.listImages();
    Image result = null;
    for (Image image : images) {
        System.out.println("  " + image);
        if (image.getOperatingSystem().getName().equals("Ubuntu 12.04 LTS (Precise Pangolin)")) {
            result = image;
        }
    }
    if (result == null) {
        System.err.println("Image with Ubuntu 12.04 operating system not found. Using first image found.");
        result = images.iterator().next();
    }
    return result;
}
Also used : Image(org.jclouds.compute.domain.Image)

Example 5 with Image

use of org.jclouds.compute.domain.Image in project whirr by apache.

the class RunningInstanceToNodeMetadata method apply.

@Override
public NodeMetadata apply(final RunningInstance instance) {
    String id = checkNotNull(instance, "instance").getId();
    // user doesn't determine a node name;
    String name = null;
    // no uri to get rest access to host info
    URI uri = null;
    String tag = getTagForInstace(instance);
    Credentials credentials = getCredentialsForInstanceWithTag(instance, tag);
    Map<String, String> userMetadata = ImmutableMap.<String, String>of();
    NodeState state = instanceToNodeState.get(instance.getInstanceState());
    Set<String> publicAddresses = nullSafeSet(instance.getIpAddress());
    Set<String> privateAddresses = nullSafeSet(instance.getPrivateIpAddress());
    Map<String, String> extra = getExtra(instance);
    Location location = getLocationForAvailabilityZone(instance);
    Image image = resolveImageForInstanceInLocation(instance, location);
    return new NodeMetadataImpl(id, name, instance.getRegion() + "/" + instance.getId(), location, uri, userMetadata, tag, image, state, publicAddresses, privateAddresses, extra, credentials);
}
Also used : NodeState(org.jclouds.compute.domain.NodeState) NodeMetadataImpl(org.jclouds.compute.domain.internal.NodeMetadataImpl) Image(org.jclouds.compute.domain.Image) URI(java.net.URI) Credentials(org.jclouds.domain.Credentials) Location(org.jclouds.domain.Location)

Aggregations

Image (org.jclouds.compute.domain.Image)5 Exchange (org.apache.camel.Exchange)2 Test (org.junit.Test)2 Joiner (com.google.common.base.Joiner)1 Predicate (com.google.common.base.Predicate)1 URI (java.net.URI)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 InstanceTemplate (org.apache.whirr.InstanceTemplate)1 AWSEC2ComputeService (org.jclouds.aws.ec2.compute.AWSEC2ComputeService)1 AWSEC2TemplateOptions (org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions)1 ComputeService (org.jclouds.compute.ComputeService)1 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)1 NodeState (org.jclouds.compute.domain.NodeState)1 Template (org.jclouds.compute.domain.Template)1 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)1 NodeMetadataImpl (org.jclouds.compute.domain.internal.NodeMetadataImpl)1 TemplateOptions (org.jclouds.compute.options.TemplateOptions)1 Credentials (org.jclouds.domain.Credentials)1