use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class AbstractOpenStackIdentityService method createKeyPair.
/**
* @see com.att.cdp.zones.IdentityService#createKeyPair(com.att.cdp.zones.model.KeyPair)
*/
@SuppressWarnings("nls")
@Override
public KeyPair createKeyPair(KeyPair keyPair) throws ZoneException {
trackRequest();
RequestState.put(RequestState.KEYPAIR, keyPair.getName());
Context context = getContext();
if (context.isLoggedIn()) {
NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
com.woorea.openstack.nova.model.KeyPair pair;
try {
pair = connector.getClient().keyPairs().create(keyPair.getName()).execute();
} catch (OpenStackConnectException e) {
throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Compute", connector.getEndpoint()), e);
} catch (OpenStackResponseException e) {
String reason = null;
if (e.getResponse() != null && e.getResponse().getInputStream() != null) {
try {
reason = IOUtils.toString(e.getResponse().getInputStream(), "UTF-8");
} catch (IOException e1) {
}
throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName() + " " + reason), e);
}
throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_REQUEST_FAILURE, "create key-pair " + keyPair.getName()), e);
}
return new OpenStackKeyPair(context, pair);
}
throw new ZoneException("Unable to create 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 AbstractOpenStackIdentityService method deleteKeyPair.
/**
* @see com.att.cdp.zones.IdentityService#deleteKeyPair(com.att.cdp.zones.model.KeyPair)
*/
@SuppressWarnings("nls")
@Override
public void deleteKeyPair(KeyPair keyPair) throws ZoneException {
trackRequest();
RequestState.put(RequestState.KEYPAIR, keyPair.getName());
Context context = getContext();
if (context.isLoggedIn()) {
NovaConnector connector = ((OpenStackContext) context).getNovaConnector();
try {
connector.getClient().keyPairs().delete(keyPair.getName()).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, "delete key-pair " + keyPair.getName()), e);
}
return;
}
throw new ZoneException("Unable to delete 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 AbstractOpenStackIdentityService method getRoles.
/**
* @see com.att.cdp.zones.IdentityService#getRoles()
*/
@SuppressWarnings("nls")
@Override
public List<String> getRoles() throws ZoneException {
trackRequest();
Context context = getContext();
ArrayList<String> list = new ArrayList<>();
if (context.isLoggedIn()) {
try {
keystoneUrl = context.getProperties().getProperty(ContextFactory.PROPERTY_IDENTITY_URL);
// tenantName = context.getProperties().getProperty(ContextFactory.PROPERTY_TENANT);
Keystone keystone = new Keystone(keystoneUrl);
OpenStackRequest<Roles> request = new OpenStackRequest<>(keystone, HttpMethod.GET, "/users/" + context.getPrincipal() + "/roles", null, Roles.class);
Roles roles;
try {
roles = keystone.execute(request);
} catch (OpenStackConnectException e) {
throw new ContextConnectionException(EELFResourceManager.format(OSMsg.PAL_OS_CONNECTION_FAILED, "Identity", keystoneUrl), e);
}
for (Role role : roles.getList()) {
list.add(role.getName());
}
} catch (OpenStackResponseException e) {
if (e.getStatus() == 404) {
throw new ResourceNotFoundException("Attempt to get roles for user " + context.getPrincipal(), e);
}
throw new ZoneException("Attempt to get roles for user " + context.getPrincipal(), e);
}
}
return list;
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method abortResize.
/**
* @see com.att.cdp.zones.ComputeService#abortResize(com.att.cdp.zones.model.Server)
*/
@SuppressWarnings("nls")
@Override
public void abortResize(Server server) throws ZoneException {
checkArg(server, "server");
checkArg(server.getId(), "server id");
connect();
trackRequest();
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
OpenStackResponse request = nova.getClient().servers().revertResize(server.getId()).request();
if (request != null && request.getStatus() != Status.ACCEPTED.getStatusCode()) {
throw new ZoneException(request.getEntity(String.class));
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method deleteServer.
/**
* Delete the specified server using it's id.
*
* @param serverId
* The server to be deleted.
* @throws ZoneException
* If the server does not exist or cannot be deleted for some reason.
* @see com.att.cdp.zones.ComputeService#deleteServer(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public void deleteServer(String serverId) throws ZoneException {
checkArg(serverId, "serverId");
connect();
trackRequest();
RequestState.put(RequestState.SERVER, serverId);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
try {
Server server = getServer(serverId);
Server.Status status = server.getStatus();
RequestState.put(RequestState.STATUS, status.toString());
if (status.equals(Server.Status.RUNNING) || status.equals(Server.Status.READY) || status.equals(Server.Status.ERROR)) {
List<Port> ports = server.getPorts();
for (Port port : ports) {
port.delete();
}
nova.getClient().servers().delete(serverId).execute();
} else {
throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId().toString(), status.toString(), StringHelper.asList(Arrays.asList(Server.Status.READY.toString(), Server.Status.RUNNING.toString(), Server.Status.ERROR.toString()))));
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
}
Aggregations