Search in sources :

Example 21 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class TestComputeService method testGetServerLazy.

/**
 * @throws ZoneException
 *             If the connection fails or the server cant be found
 * @throws IllegalAccessException
 *             If the fields cant be accessed
 * @throws IllegalArgumentException
 *             If the fields cant be accessed
 */
@Ignore
@Test
public void testGetServerLazy() throws ZoneException, IllegalArgumentException, IllegalAccessException {
    Context context = connect();
    ComputeService computeService = context.getComputeService();
    Server server = computeService.getServer(TEST_SERVER_UUID);
    /*
         * Make sure that we have not obtained any of the transitive dependencies yet
         */
    assertNotNull(server);
    AtomicBoolean ab = (AtomicBoolean) volumeAttachmentsProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    ab = (AtomicBoolean) imagesProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    ab = (AtomicBoolean) networksProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    /*
         * Now, get the network and ensure that it is correct
         */
    List<Network> networks = server.getNetworks();
    assertNotNull(networks);
    assertFalse(networks.isEmpty());
    boolean found = false;
    for (Network network : networks) {
        if (network.getName().equals(TEST_NETWORK_NAME)) {
            found = true;
            break;
        }
    }
    assertTrue(found);
    ab = (AtomicBoolean) networksProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
    ab = (AtomicBoolean) volumeAttachmentsProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    ab = (AtomicBoolean) imagesProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    /*
         * Now, determine the boot source and image, this will cause the images to be processed
         */
    ServerBootSource bs = server.getBootSource();
    assertNotNull(bs);
    assertTrue(bs.equals(ServerBootSource.IMAGE) || bs.equals(ServerBootSource.SNAPSHOT));
    String image = server.getImage();
    assertNotNull(image);
    ab = (AtomicBoolean) networksProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
    ab = (AtomicBoolean) imagesProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
    ab = (AtomicBoolean) volumeAttachmentsProcessedField.get(server);
    assertNotNull(ab);
    assertFalse(ab.get());
    /*
         * Now, lets see if there are any volume attachments. This will load the volumes transitive relationship
         */
    Map<String, Volume> volumes = server.getVolumes();
    assertNotNull(volumes);
    ab = (AtomicBoolean) networksProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
    ab = (AtomicBoolean) imagesProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
    ab = (AtomicBoolean) volumeAttachmentsProcessedField.get(server);
    assertNotNull(ab);
    assertTrue(ab.get());
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) Server(com.att.cdp.zones.model.Server) Volume(com.att.cdp.zones.model.Volume) Network(com.att.cdp.zones.model.Network) ServerBootSource(com.att.cdp.zones.model.ServerBootSource) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class TestComputeService method testComputeService.

/**
 * @throws ZoneException
 *             If something goes horribly wrong
 */
@Ignore
@Test
public void testComputeService() throws ZoneException {
    Context context = connect();
    ComputeService computeService = context.getComputeService();
    List<Server> servers = computeService.getServers();
    for (Server server : servers) {
        computeService.getServers(server.getName());
        computeService.getServer(server.getId());
        computeService.getAttachments(server);
        computeService.getAttachments(server.getId());
        computeService.getConsoleOutput(server);
    }
    List<Template> templates = computeService.getTemplates();
    for (Template template : templates) {
        computeService.getTemplate(template.getId());
    }
    List<ACL> accessControlLists = computeService.getAccessControlLists();
    for (ACL acl : accessControlLists) {
        computeService.getAccessControlList(acl.getId());
    }
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) Server(com.att.cdp.zones.model.Server) ACL(com.att.cdp.zones.model.ACL) ComputeService(com.att.cdp.zones.ComputeService) Template(com.att.cdp.zones.model.Template) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class TestComputeService method testRebuildServer.

/**
 * This test is designed to rebuild a specific server and test that it rebuilds correctly
 *
 * @throws ZoneException
 *             If something goes horribly wrong
 */
@SuppressWarnings("nls")
@Ignore
@Test
public void testRebuildServer() throws ZoneException {
    Context context = connect();
    ComputeService computeService = context.getComputeService();
    Server testVNF = computeService.getServer(TEST_SERVER_UUID);
    testVNF.rebuild();
    testVNF.waitForStateChange(1, 600, Server.Status.RUNNING);
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) Server(com.att.cdp.zones.model.Server) ComputeService(com.att.cdp.zones.ComputeService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class TestComputeService method testOpenstackMigrate.

@Ignore
@Test
public void testOpenstackMigrate() throws ZoneException {
    // For testing the migrate functionality
    Properties properties = new Properties();
    String vmId = "75dce20c-97f9-454d-abcc-aa904a33df5a";
    properties.put(ContextFactory.PROPERTY_IDENTITY_URL, "http://135.25.246.131:5000");
    properties.put(ContextFactory.PROPERTY_TENANT, "Play");
    // String vmId = "af51c8b9-3df4-4770-846a-457666367b23";
    // properties.put(ContextFactory.PROPERTY_IDENTITY_URL, "http://135.25.69.195:5000");
    // properties.put(ContextFactory.PROPERTY_TENANT, "Trinity");
    OpenStackContext context = (OpenStackContext) ContextFactory.getContext("OpenStackProvider", properties);
    context.login("AppC", "AppC");
    ComputeService computeService = context.getComputeService();
    Server testVNF = computeService.getServer(vmId);
    long t1, t2, t3, t4;
    t1 = System.currentTimeMillis() / 1000;
    computeService.migrateServer(testVNF.getId());
    testVNF.waitForStateChange(1, 600, Status.PENDING);
    t2 = System.currentTimeMillis() / 1000;
    System.out.println("Migrate accepted and calculating prep work");
    try {
        computeService.migrateServer(testVNF.getId());
        fail("Should not be able to migrate a server that is in PENDING");
    } catch (Exception e) {
    // Good
    }
    try {
        computeService.processResize(testVNF);
        fail("Should not be able to confirm a resize on a server that is in PENDING");
    } catch (Exception e) {
    // Good
    }
    testVNF.waitForStateChange(5, 600, Status.READY);
    t3 = System.currentTimeMillis() / 1000;
    System.out.println("Migrate calculations does. Send resizeConfirm to apply");
    computeService.processResize(testVNF);
    testVNF.waitForStateChange(1, 600, Status.RUNNING);
    t4 = System.currentTimeMillis() / 1000;
// System.out.println("Migrate Complete. Time to: 1) Start checking after migrate() call, 2) Finish checking, 3) Commit migrate");
// System.out.println(String.format("1) %3ds\n2) %3ds (%03ds)\n3) %3ds (%3ds)", t2 - t1, t3 - t2, t3 - t1,
// t4 - t3, t4 - t1));
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) Server(com.att.cdp.zones.model.Server) Properties(java.util.Properties) ComputeService(com.att.cdp.zones.ComputeService) ZoneException(com.att.cdp.exceptions.ZoneException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with Server

use of com.att.cdp.zones.model.Server in project AJSC by att.

the class OpenStackServer method loadNetworks.

/**
 * This method lazily loads the networks and ip addresses of the server
 *
 * @param context
 *            The context we are servicing
 */
@SuppressWarnings("nls")
private void loadNetworks(Context context) {
    if (networksProcessed.compareAndSet(false, true)) {
        try {
            NetworkService netService = context.getNetworkService();
            com.woorea.openstack.nova.model.Server.Addresses addresses = novaModel.getAddresses();
            if (addresses != null) {
                for (Map.Entry<String, List<com.woorea.openstack.nova.model.Server.Addresses.Address>> entry : addresses.getAddresses().entrySet()) {
                    String netName = entry.getKey();
                    try {
                        List<Network> nets = netService.getNetworksByName(netName);
                        if (!nets.isEmpty()) {
                            getNetworks().add(nets.get(0));
                        }
                        for (com.woorea.openstack.nova.model.Server.Addresses.Address osAddr : entry.getValue()) {
                            String type = osAddr.getType();
                            if (type != null) {
                                if (type.equalsIgnoreCase("fixed")) {
                                    getFixedAddresses().add(osAddr.getAddr());
                                } else {
                                    getFloatingAddresses().add(osAddr.getAddr());
                                }
                            }
                        }
                    } catch (ZoneException e) {
                        LOG.error(EELFResourceManager.format(e));
                    }
                }
            }
        } catch (Exception e) {
            LOG.error(String.format("Unexpected exception %s retrieving addresses for server %s", e.getClass().getSimpleName(), getId()));
            LOG.error(EELFResourceManager.format(e));
        }
    }
}
Also used : ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) Server(com.att.cdp.zones.model.Server) ZoneException(com.att.cdp.exceptions.ZoneException) ZoneException(com.att.cdp.exceptions.ZoneException) Network(com.att.cdp.zones.model.Network) NetworkService(com.att.cdp.zones.NetworkService) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Server (com.att.cdp.zones.model.Server)26 Context (com.att.cdp.zones.Context)22 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)17 OpenStackContext (com.att.cdp.openstack.OpenStackContext)16 Ignore (org.junit.Ignore)13 ComputeService (com.att.cdp.zones.ComputeService)12 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)12 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)11 Test (org.junit.Test)11 ZoneException (com.att.cdp.exceptions.ZoneException)9 ArrayList (java.util.ArrayList)7 Port (com.att.cdp.zones.model.Port)6 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)4 NetworkService (com.att.cdp.zones.NetworkService)4 Network (com.att.cdp.zones.model.Network)4 Servers (com.woorea.openstack.nova.model.Servers)4 HashMap (java.util.HashMap)4 ACL (com.att.cdp.zones.model.ACL)3 Subnet (com.att.cdp.zones.model.Subnet)3 List (java.util.List)3