Search in sources :

Example 1 with ImageService

use of com.att.cdp.zones.ImageService in project AJSC by att.

the class TestOpenStackContext method testLoginLogout.

/**
 * Test that we can login and out of the provider, and access the services once logged in (so we dont have to
 * repeatedly login/out)
 *
 * @throws ZoneException
 */
@Test
@Ignore
public void testLoginLogout() throws ZoneException {
    OpenStackContext context = login();
    /*
         * make sure we can retreive all of the services
         */
    ComputeService computeService = context.getComputeService();
    assertNotNull(computeService);
    IdentityService identityService = context.getIdentityService();
    assertNotNull(identityService);
    ImageService imageService = context.getImageService();
    assertNotNull(imageService);
    NetworkService networkService = context.getNetworkService();
    assertNotNull(networkService);
    VolumeService volumeService = context.getVolumeService();
    assertNotNull(volumeService);
    SnapshotService snapshotService = context.getSnapshotService();
    assertNotNull(snapshotService);
    StackService stackService = context.getStackService();
    assertNotNull(stackService);
    /*
         * Services are locally cached by the provider context. If we get them again, we should get the same exact
         * object. Check that too.
         */
    assertTrue(computeService == context.getComputeService());
    assertTrue(identityService == context.getIdentityService());
    assertTrue(imageService == context.getImageService());
    assertTrue(networkService == context.getNetworkService());
    assertTrue(volumeService == context.getVolumeService());
    assertTrue(snapshotService == context.getSnapshotService());
    assertTrue(stackService == context.getStackService());
    /*
         * Test that we can also obtain the connectors
         */
    GlanceConnector glanceConnector = context.getGlanceConnector();
    assertNotNull(glanceConnector);
    NovaConnector novaConnector = context.getNovaConnector();
    assertNotNull(novaConnector);
    QuantumConnector quantumConnector = context.getQuantumConnector();
    assertNotNull(quantumConnector);
    /*
         * Connectors are locally cached, check that
         */
    assertTrue(glanceConnector == context.getGlanceConnector());
    assertTrue(novaConnector == context.getNovaConnector());
    assertTrue(quantumConnector == context.getQuantumConnector());
    /*
         * Now, check that we can obtain the tenant as well
         */
    Tenant tenant = context.getTenant();
    assertNotNull(tenant);
    assertEquals(tenant.getName(), context.getTenantName());
    assertEquals(tenant.getId(), context.getTenantId());
    logout(context);
}
Also used : IdentityService(com.att.cdp.zones.IdentityService) SnapshotService(com.att.cdp.zones.SnapshotService) StackService(com.att.cdp.zones.StackService) Tenant(com.att.cdp.zones.model.Tenant) GlanceConnector(com.att.cdp.openstack.connectors.GlanceConnector) VolumeService(com.att.cdp.zones.VolumeService) QuantumConnector(com.att.cdp.openstack.connectors.QuantumConnector) NetworkService(com.att.cdp.zones.NetworkService) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackComputeService(com.att.cdp.openstack.v2.OpenStackComputeService) ComputeService(com.att.cdp.zones.ComputeService) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ImageService

use of com.att.cdp.zones.ImageService in project AJSC by att.

the class TestImages method listImages.

/**
 * Verifies that we can list the existing templates on a provider. This test requires that the provider actually has
 * templates installed.
 *
 * @throws ZoneException
 */
@Ignore
@Test
public void listImages() throws ZoneException {
    Context context = connect();
    ImageService service = context.getImageService();
    List<Image> images = service.listImages();
    assertNotNull(images);
    assertFalse(images.isEmpty());
    for (Image image : images) {
        System.out.println(image.toString());
    }
}
Also used : Context(com.att.cdp.zones.Context) Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ImageService

use of com.att.cdp.zones.ImageService in project AJSC by att.

the class TestImages method getImages.

/**
 * Verifies that we can list the existing templates on a provider. This test requires that the provider actually has
 * templates installed.
 *
 * @throws ZoneException
 */
// @Ignore
@Test
@Ignore
public void getImages() throws ZoneException {
    Context context = connect();
    ImageService service = context.getImageService();
    List<Image> images = service.listImages();
    assertNotNull(images);
    assertFalse(images.isEmpty());
    for (Image image : images) {
        service.getImage(image.getId());
    }
}
Also used : Context(com.att.cdp.zones.Context) Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ImageService

use of com.att.cdp.zones.ImageService in project AJSC by att.

the class OpenStackServer method loadImageAndBootSource.

/**
 * This method loads the actual image object that the server was booted from, and also determines if there are any
 * snapshots of that image created from this server. If there are, it populates the snapshot list as well and sorts
 * that list into chronological order, most recent first.
 *
 * @param context
 *            The context we are servicing
 */
@SuppressWarnings("nls")
private void loadImageAndBootSource(Context context) {
    if (imagesProcessed.compareAndSet(false, true)) {
        /*
             * Now, lookup the image and attach it to the server
             */
        Image bootImage = null;
        if (novaModel.getImage() != null) {
            try {
                String serverImageId = novaModel.getImage().getId();
                ImageService imageService = context.getImageService();
                List<Image> images = imageService.listImages();
                for (Image image : images) {
                    if (image.getId().equals(serverImageId)) {
                        bootImage = image;
                    }
                    if (image.getImageType().equals(Image.Type.SNAPSHOT) && getId().equals(image.getInstanceId())) {
                        getSnapshots().add(image);
                    }
                }
            } catch (Exception e) {
                LOG.error(String.format("Unexpected exception %s retrieving images for server %s", e.getClass().getSimpleName(), getId()));
                LOG.error(EELFResourceManager.format(e));
            }
        }
        /*
             * Sort the snapshots into chronological order (newest first) if any snapshots exist
             */
        if (!getSnapshots().isEmpty()) {
            Collections.sort(getSnapshots(), new Comparator<Image>() {

                @Override
                public int compare(Image o1, Image o2) {
                    if (o2.getCreatedDate().before(o1.getCreatedDate())) {
                        return -1;
                    } else if (o2.getCreatedDate().after(o1.getCreatedDate())) {
                        return 1;
                    }
                    return 0;
                }
            });
        }
        if (bootImage == null) {
            setBootSource(ServerBootSource.VOLUME);
            setImage(null);
        } else {
            if (bootImage.getImageType().equals(Image.Type.SNAPSHOT)) {
                setBootSource(ServerBootSource.SNAPSHOT);
            } else {
                setBootSource(ServerBootSource.IMAGE);
            }
            setImage(bootImage);
        }
    }
}
Also used : Image(com.att.cdp.zones.model.Image) ImageService(com.att.cdp.zones.ImageService) ZoneException(com.att.cdp.exceptions.ZoneException)

Aggregations

ImageService (com.att.cdp.zones.ImageService)4 Image (com.att.cdp.zones.model.Image)3 Ignore (org.junit.Ignore)3 Test (org.junit.Test)3 Context (com.att.cdp.zones.Context)2 ZoneException (com.att.cdp.exceptions.ZoneException)1 GlanceConnector (com.att.cdp.openstack.connectors.GlanceConnector)1 NovaConnector (com.att.cdp.openstack.connectors.NovaConnector)1 QuantumConnector (com.att.cdp.openstack.connectors.QuantumConnector)1 OpenStackComputeService (com.att.cdp.openstack.v2.OpenStackComputeService)1 ComputeService (com.att.cdp.zones.ComputeService)1 IdentityService (com.att.cdp.zones.IdentityService)1 NetworkService (com.att.cdp.zones.NetworkService)1 SnapshotService (com.att.cdp.zones.SnapshotService)1 StackService (com.att.cdp.zones.StackService)1 VolumeService (com.att.cdp.zones.VolumeService)1 Tenant (com.att.cdp.zones.model.Tenant)1