Search in sources :

Example 36 with ZoneException

use of com.att.cdp.exceptions.ZoneException 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)

Example 37 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class AbstractOpenStackIdentityService method getTenant.

/**
 * All services must be able to return the tenant object that the user has connected to.
 *
 * @return The tenant object
 * @throws ZoneException
 *             If the user has not logged in
 * @see com.att.cdp.zones.Service#getTenant()
 */
@Override
public Tenant getTenant() throws ZoneException {
    checkLoggedIn();
    Context context = getContext();
    trackRequest();
    Keystone keystone = getKeystone();
    keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
    if (tenant == null) {
        com.woorea.openstack.keystone.model.Tenants tenants;
        try {
            tenants = keystone.tenants().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get tenant " + tenantName), e);
        }
        for (com.woorea.openstack.keystone.model.Tenant t : tenants) {
            if (t.getName().equals(tenantName)) {
                tenant = new OpenStackTenant((OpenStackContext) context, t);
                break;
            }
        }
    }
    return tenant;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackTenant(com.att.cdp.openstack.model.OpenStackTenant) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Tenants(com.woorea.openstack.keystone.model.Tenants) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 38 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class AbstractOpenStackIdentityService method getKeyPairs.

/**
 * @see com.att.cdp.zones.IdentityService#getKeyPairs()
 */
@SuppressWarnings("nls")
@Override
public List<KeyPair> getKeyPairs() throws ZoneException {
    trackRequest();
    Context context = getContext();
    if (context.isLoggedIn()) {
        NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
        KeyPairs pairs = null;
        try {
            pairs = connector.getClient().keyPairs().list().execute();
        } catch (OpenStackConnectException e) {
            throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
        } catch (OpenStackResponseException e) {
            throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "get key-pair list"), e);
        }
        ArrayList<KeyPair> list = new ArrayList<>();
        for (com.woorea.openstack.nova.model.KeyPair pair : pairs.getList()) {
            OpenStackKeyPair kp = new OpenStackKeyPair(context, pair);
            list.add(kp);
        }
        return list;
    }
    throw new ZoneException("Unable to retrieve key-pairs when the context has not been logged in and authenticated");
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) KeyPair(com.att.cdp.zones.model.KeyPair) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) KeyPairs(com.woorea.openstack.nova.model.KeyPairs) ArrayList(java.util.ArrayList) OpenStackContext(com.att.cdp.openstack.OpenStackContext) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) OpenStackKeyPair(com.att.cdp.openstack.model.OpenStackKeyPair) NovaConnector(com.att.cdp.openstack.connectors.NovaConnector) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 39 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class TestConnectedKeyPair method testConnectedKeyPair.

/**
 * Verify the object is not null
 *
 * @throws ZoneException
 */
@Test
public void testConnectedKeyPair() throws ZoneException {
    ConnectedKeyPair keyPair = new ConnectedKeyPair(context);
    assertNotNull(keyPair);
    keyPair.setCreatedBy("bg6954");
    Date creDate = new Date();
    keyPair.setCreatedDate(creDate);
    keyPair.setUpdatedBy("bhanu");
    Date upDate = new Date();
    keyPair.setUpdatedDate(upDate);
    keyPair.setDeletedBy("ramesh");
    Date delDate = new Date();
    keyPair.setDeletedDate(delDate);
    assertTrue(keyPair.isConnected());
    assertNotNull(keyPair);
    assertEquals("bg6954", keyPair.getCreatedBy());
    assertEquals("bhanu", keyPair.getUpdatedBy());
    assertEquals("ramesh", keyPair.getDeletedBy());
    assertEquals(delDate, keyPair.getDeletedDate());
    assertEquals(creDate, keyPair.getCreatedDate());
    assertEquals(upDate, keyPair.getUpdatedDate());
    keyPair.setPrivateKey("privatekey");
    keyPair.setPublicKey("publickey");
    keyPair.setFingerprint("fingerprint");
    keyPair.setName("name");
    keyPair.setUserId("userId");
    assertEquals(keyPair.getPrivateKey(), "privatekey");
    // @sonar:off
    try {
        assertEquals(keyPair.getPublicKey(), "publickey");
    } catch (ZoneException e) {
    // ignore
    }
    assertEquals(keyPair.getFingerprint(), "fingerprint");
    try {
        keyPair.getTenant();
    } catch (Exception e) {
    // ignore
    }
    assertEquals(keyPair.getUserId(), "userId");
    try {
        keyPair.delete();
    } catch (Exception e) {
    // ignore
    }
// @sonar:on
}
Also used : ZoneException(com.att.cdp.exceptions.ZoneException) Date(java.util.Date) ZoneException(com.att.cdp.exceptions.ZoneException) NotNavigableException(com.att.cdp.exceptions.NotNavigableException) Test(org.junit.Test)

Example 40 with ZoneException

use of com.att.cdp.exceptions.ZoneException in project AJSC by att.

the class TestTenant method testConnectedTenant.

/**
 * tests that once a context exists and a login has occurred, that the tenant object can be obtained
 */
@SuppressWarnings("unused")
@Test
public void testConnectedTenant() {
    Tenant tenant;
    try {
        tenant = context.getTenant();
        assertNotNull(tenant);
    // Context ctx = tenant.getContext();
    } catch (ZoneException e1) {
        e1.printStackTrace();
        fail("Should have succeeded!");
    }
}
Also used : Tenant(com.att.cdp.zones.model.Tenant) ZoneException(com.att.cdp.exceptions.ZoneException) Test(org.junit.Test)

Aggregations

ZoneException (com.att.cdp.exceptions.ZoneException)40 Context (com.att.cdp.zones.Context)30 OpenStackContext (com.att.cdp.openstack.OpenStackContext)18 NetworkService (com.att.cdp.zones.NetworkService)15 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)15 Test (org.junit.Test)15 Network (com.att.cdp.zones.model.Network)13 Ignore (org.junit.Ignore)13 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)11 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)11 Server (com.att.cdp.zones.model.Server)9 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)8 Subnet (com.att.cdp.zones.model.Subnet)8 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)8 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)6 InvalidRequestException (com.att.cdp.exceptions.InvalidRequestException)5 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)5 ContextClosedException (com.att.cdp.exceptions.ContextClosedException)4