use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method getAttachments.
/**
* Returns a map of the volume attachments for the specified server. The key of the map is the device name for the
* volume attachment. This is the device identification which the server will "see".
*
* @param id
* The server ID for which we wish to obtain all attachments (if any).
* @return A map of the volume attachments, or an empty map if there are none. The map is keyed by the device name
* used to attach the volume. The value of the entry is the ID of the volume attached at that device.
* @throws ZoneException
* - If the attachments cannot be obtained
* @see com.att.cdp.zones.ComputeService#getAttachments(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public Map<String, String> getAttachments(String id) throws ZoneException {
checkArg(id, "id");
connect();
trackRequest();
RequestState.put(RequestState.SERVER, id);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
HashMap<String, String> map = new HashMap<>();
try {
for (VolumeAttachment attachment : nova.getClient().servers().listVolumeAttachments(id).execute()) {
RequestState.put(RequestState.VOLUME, attachment.getVolumeId());
if (attachment.getDevice() != null) {
RequestState.put(RequestState.DEVICE, attachment.getDevice());
map.put(attachment.getDevice(), attachment.getVolumeId());
} else {
System.err.println("No device found for " + attachment);
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
} catch (Exception e) {
throw new ZoneException("Error obtaining volume attachments.", e);
}
return map;
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method migrateServer.
/**
* @see com.att.cdp.zones.ComputeService#migrateServer(java.lang.String)
*/
@Override
public void migrateServer(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 {
OpenStackResponse response = nova.getClient().servers().migrate(serverId).request();
if (response == null || response.getStatus() != Status.ACCEPTED.getStatusCode()) {
throw new ZoneException(response.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 getAttachments.
/**
* Returns a map of the volume attachments for the specified server. The key
* of the map is the device name for the volume attachment. This is the
* device identification which the server will "see".
*
* @param id
* The server ID for which we wish to obtain all attachments (if
* any).
* @return A map of the volume attachments, or an empty map if there are
* none. The map is keyed by the device name used to attach the
* volume. The value of the entry is the ID of the volume attached
* at that device.
* @throws ZoneException
* - If the attachments cannot be obtained
* @see com.att.cdp.zones.ComputeService#getAttachments(java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public Map<String, String> getAttachments(String id) throws ZoneException {
checkArg(id, "id");
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVER, id);
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
HashMap<String, String> map = new HashMap<>();
try {
for (VolumeAttachment attachment : nova.getClient().servers().listVolumeAttachments(id).execute()) {
RequestState.put(RequestState.VOLUME, attachment.getVolumeId());
if (attachment.getDevice() != null) {
RequestState.put(RequestState.DEVICE, attachment.getDevice());
map.put(attachment.getDevice(), attachment.getVolumeId());
} else {
System.err.println("No device found for " + attachment);
}
}
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
} catch (Exception e) {
throw new ZoneException("Error obtaining volume attachments.", e);
}
return map;
}
use of com.att.cdp.exceptions.ZoneException in project AJSC by att.
the class OpenStackComputeService method attachVolume.
/**
* Attach a volume to a specified server. The volume is then attached to the
* server for it to use when the server is started.
*
* @param server
* The server we are manipulating
* @param volume
* The volume we wish to attach to the server
* @param deviceName
* the name of the device presented to the server
* @throws ZoneException
* If the volume cannot be attached for some reason
* @see com.att.cdp.zones.ComputeService#attachVolume(com.att.cdp.zones.model.Server,
* com.att.cdp.zones.model.Volume, java.lang.String)
*/
@SuppressWarnings("nls")
@Override
public void attachVolume(Server server, Volume volume, String deviceName) throws ZoneException {
checkArg(server, "server");
checkArg(volume, "volume");
checkArg(deviceName, "deviceName");
if (!checkDeviceName(deviceName)) {
throw new InvalidRequestException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_DEVICE_NAME, deviceName));
}
connect();
Context context = getContext();
trackRequest();
RequestState.put(RequestState.SERVER, server);
RequestState.put(RequestState.VOLUME, volume.getId());
RequestState.put(RequestState.DEVICE, volume.getId());
RequestState.put(RequestState.SERVICE, "Compute");
RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
/*
* Get the list of existing attachments and check to see if the device
* name is already used
*/
Map<String, String> attachments = getAttachments(server);
if (attachments.containsKey(deviceName)) {
throw new InvalidRequestException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_DEVICE_NAME, deviceName));
}
/*
* Check the server status to see if it is correct for attempting the
* attachment
*/
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().attachVolume(server.getId(), volume.getId(), deviceName).execute();
} catch (OpenStackBaseException ex) {
ExceptionMapper.mapException(ex);
}
} else {
throw new ZoneException(EELFResourceManager.format(OSMsg.PAL_OS_INVALID_SERVER_STATE, server.getName(), server.getId().toString(), status.toString(), EELFResourceManager.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 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();
Context context = getContext();
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);
}
}
Aggregations