Search in sources :

Example 21 with ZoneException

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;
}
Also used : VolumeAttachment(com.woorea.openstack.nova.model.VolumeAttachment) ZoneException(com.att.cdp.exceptions.ZoneException) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ContextClosedException(com.att.cdp.exceptions.ContextClosedException) NotLoggedInException(com.att.cdp.exceptions.NotLoggedInException)

Example 22 with ZoneException

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);
    }
}
Also used : OpenStackResponse(com.woorea.openstack.base.client.OpenStackResponse) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 23 with ZoneException

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;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) VolumeAttachment(com.woorea.openstack.nova.model.VolumeAttachment) ZoneException(com.att.cdp.exceptions.ZoneException) HashMap(java.util.HashMap) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ContextClosedException(com.att.cdp.exceptions.ContextClosedException) NotLoggedInException(com.att.cdp.exceptions.NotLoggedInException)

Example 24 with ZoneException

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())));
    }
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) Server(com.att.cdp.zones.model.Server) ConnectedServer(com.att.cdp.zones.spi.model.ConnectedServer) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) InvalidRequestException(com.att.cdp.exceptions.InvalidRequestException)

Example 25 with ZoneException

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);
    }
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackResponse(com.woorea.openstack.base.client.OpenStackResponse) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

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