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));
}
}
}
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;
}
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");
}
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
}
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!");
}
}
Aggregations