use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method detachVolume.
/**
* Detaches the volume from the specified server.
*
* @param server
* The server to be manipulated
* @param volume
* The volume to be detached
* @throws ZoneException
* - If the volume cannot be detached for some reason
* @see com.att.cdp.zones.ComputeService#detachVolume(com.att.cdp.zones.model.Server,
* com.att.cdp.zones.model.Volume)
*/
@SuppressWarnings("nls")
@Override
public void detachVolume(Server server, Volume volume) throws ZoneException {
checkArg(server, "server");
checkArg(volume, "volume");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVER, server.getName());
RequestState.put(RequestState.VOLUME, volume.getName());
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
server.refreshStatus();
Server.Status status = server.getStatus();
RequestState.put(RequestState.STATUS, status.toString());
if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY)) {
try {
nova.getClient().servers().detachVolume(server.getId(), volume.getId()).execute();
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
} else {
throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString()))));
}
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method getTemplate.
/**
* Obtains the template specified by the provided id
*
* @see com.att.cdp.zones.ComputeService#getTemplate(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public Template getTemplate(String id) throws ZoneException {
checkArg(id, "id");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
RequestState.put(RequestState.TEMPLATE, id);
try {
return new OpenStackTemplate(context, nova.getClient().flavors().show(id).execute());
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
} catch (Exception e) {
throw new ResourceNotFoundException(e);
}
// for the compiler
return null;
}
use of com.att.cdp.exceptions.ZoneException 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));
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class TestNetworkService method testLoadBalancer.
/**
* Verifies all load balancer apis
*
* @throws ZoneException
* If the connection fails, user is not authorized, or the provider cannot perform the operation.
*/
@Ignore
@Test
public void testLoadBalancer() throws ZoneException {
Context context = connect();
NetworkService service = context.getNetworkService();
String poolName = "TestNewPool";
String tenantId = context.getTenant().getId();
String subnetId = "2de8b5a0-1f7d-4736-8655-874c506e8f1b";
// Step 1: Check if pool exists with this name
LoadBalancerPool loadBalancerPool = null;
try {
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
if (loadBalancePools.size() == 1) {
loadBalancerPool = loadBalancePools.get(0);
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to find the pool with name: " + ze.getMessage());
}
// Step 2: If pool exists delete it
if (loadBalancerPool != null) {
try {
service.deleteLoadBalancerPool(loadBalancerPool);
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
assertEquals(loadBalancePools.size(), 0);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer pool: " + ze.getMessage());
}
}
// Step 3: Create a new pool
try {
LoadBalancerPool testlbPool = new LoadBalancerPool();
testlbPool.setProtocol(ProtocolType.HTTP);
testlbPool.setName(poolName);
testlbPool.setSubnetId(subnetId);
testlbPool.setLbAlgorithm(AlgorithmType.ROUND_ROBIN);
loadBalancerPool = service.createLoadBalancerPool(testlbPool);
LoadBalancerPool returnedLoadBalancerPool = service.getLoadBalancerPoolById(loadBalancerPool.getId());
assertNotNull(returnedLoadBalancerPool);
assertEquals(returnedLoadBalancerPool.getName(), poolName);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer pool: " + ze.getMessage());
}
// Step 4: Create a new load balancer vip and assign to the pool
LoadBalancerListener loadBalancerListener = null;
try {
LoadBalancerListener testlbVIP = new LoadBalancerListener();
testlbVIP.setProtocol(ProtocolType.HTTP);
testlbVIP.setName("TestNewVip");
testlbVIP.setPoolId(loadBalancerPool.getId());
testlbVIP.setSubnetId(subnetId);
loadBalancerListener = service.createLoadBalancerListener(testlbVIP);
LoadBalancerListener returnedloadBalancerVIP = service.getLoadBalancerListenerById(loadBalancerListener.getId());
assertNotNull(returnedloadBalancerVIP);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer VIP: " + ze.getMessage());
}
// Step 5: Fetch load balancer vips
try {
List<LoadBalancerListener> loadBalanceVIPs = service.getLoadBalancerListeners();
assertNotNull(loadBalanceVIPs);
for (LoadBalancerListener loadBalanceVIP : loadBalanceVIPs) {
assertNotNull(loadBalanceVIP.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to fetch the test load balancer VIPs: " + ze.getMessage());
}
// Step 7: Create load balancer health monitor
LoadBalancerHealthMonitor loadBalancerHealthMonitor = null;
try {
LoadBalancerHealthMonitor testlbHM = new LoadBalancerHealthMonitor();
testlbHM.setType(ProtocolType.PING);
testlbHM.setMaxRetries(1);
loadBalancerHealthMonitor = service.createLoadBalancerHealthMonitor(testlbHM);
LoadBalancerHealthMonitor returnedloadBalancerHealthMonitor = service.getLoadBalancerHealthMonitorById(loadBalancerHealthMonitor.getId());
assertNotNull(returnedloadBalancerHealthMonitor);
assertNotNull(returnedloadBalancerHealthMonitor.getId());
List<LoadBalancerHealthMonitor> loadBalancerHealthMonitors = service.getLoadBalancerHealthMonitors();
assertNotNull(loadBalancerHealthMonitors);
for (LoadBalancerHealthMonitor monitor : loadBalancerHealthMonitors) {
assertNotNull(monitor.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer health monitor : " + ze.getMessage());
}
// associate the health monitor to pool
try {
service.associateLoadBalancerHealthMonitorWithPool(loadBalancerPool.getId(), loadBalancerHealthMonitor.getId());
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to associate health monitor to pool: " + ze.getMessage());
}
// Step 9: Create a new load balancer member and assign to the pool
LoadBalancerMember loadBalancerMember = null;
// test load balancer vip creation
try {
LoadBalancerMember testlbMember = new LoadBalancerMember();
testlbMember.setAddress("135.144.122.19");
testlbMember.setPoolId(loadBalancerPool.getId());
loadBalancerMember = service.createLoadBalancerMember(testlbMember);
LoadBalancerMember returnedLoadBalancerMembers = service.getLoadBalancerMemberById(loadBalancerMember.getId());
assertNotNull(returnedLoadBalancerMembers);
List<LoadBalancerMember> loadBalancerMembers = service.getLoadBalancerMembers();
assertNotNull(loadBalancerMembers);
for (LoadBalancerMember loadBalancerMembe : loadBalancerMembers) {
assertNotNull(loadBalancerMembe.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test load balancer member : " + ze.getMessage());
}
// Step 10: Fetch load balancer member
try {
List<LoadBalancerMember> loadBalanceMembers = service.getLoadBalancerMembers();
assertNotNull(loadBalanceMembers);
for (LoadBalancerMember loadBalanceMember : loadBalanceMembers) {
assertNotNull(loadBalanceMember.getId());
}
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to fetch the test load balancer members: " + ze.getMessage());
}
// Step 6: Delete load balancer vip
try {
assertNotNull(loadBalancerListener);
// test network deletion
service.deleteLoadBalancerListener(loadBalancerListener);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer vip: " + ze.getMessage());
}
// disassociate the health monitor to pool
try {
service.disassociateLoadBalancerHealthMonitorWithPool(loadBalancerPool.getId(), loadBalancerHealthMonitor.getId());
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to disassociate health monitor to pool: " + ze.getMessage());
}
// Step 11: Delete load balancer member
try {
assertNotNull(loadBalancerMember);
// test network deletion
service.deleteLoadBalancerMember(loadBalancerMember);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer member: " + ze.getMessage());
}
// Step 12: pool delete
if (loadBalancerPool != null) {
try {
service.deleteLoadBalancerPool(loadBalancerPool);
List<LoadBalancerPool> loadBalancePools = service.getLoadBalancerPoolByName(poolName);
assertNotNull(loadBalancePools);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer pool: " + ze.getMessage());
}
}
// Step 8: Delete load balancer health monitor
try {
LoadBalancerHealthMonitor loadBalancerHM = service.getLoadBalancerHealthMonitorById(loadBalancerHealthMonitor.getId());
assertNotNull(loadBalancerHM);
// test network deletion
service.deleteLoadBalancerHealthMonitor(loadBalancerHM);
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to delete the test load balancer health montor: " + ze.getMessage());
}
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class TestNetworkService method testCreateNetwork.
/**
* Verifies that we can create a network on a provider.
*
* @throws ZoneException
* If the connection fails, user is not authorized, or the provider cannot perform the operation.
*/
@Test
@Ignore
public void testCreateNetwork() throws ZoneException {
Context context = connect();
NetworkService service = context.getNetworkService();
// test network creation
try {
Network testNetwork = new Network("CDP_Test_Network");
service.createNetwork(testNetwork);
List<Network> networks = service.getNetworksByName("CDP_Test_Network");
assertNotNull(networks);
assertFalse(networks.isEmpty());
} catch (ZoneException ze) {
ze.printStackTrace();
fail("Failed to create the test network");
}
}
Aggregations