Search in sources :

Example 26 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackVolumeService method getSnapshotsByVolume.

/**
 * @see com.att.cdp.zones.VolumeService#getSnapshotsByVolume(java.lang.String)
 */
@Override
public List<Snapshot> getSnapshotsByVolume(String id) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Snapshot> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Snapshots snapshots = nova.getClient().snapshots().list(true).execute();
        for (com.woorea.openstack.nova.model.Snapshot snap : snapshots) {
            if (id != null) {
                if (snap.getVolumeId() != null && snap.getVolumeId().matches(id)) {
                    list.add(new OpenStackSnapshot(context, snap));
                }
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) Snapshot(com.att.cdp.zones.model.Snapshot) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 27 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackVolumeService method connect.

/**
 * This is a helper method used to construct the Nova service object and setup the environment to access the
 * OpenStack compute service (Nova).
 *
 * @throws NotLoggedInException
 *             If the user is not logged in
 * @throws ContextClosedException
 *             If the user attempts an operation after the context is closed
 */
private void connect() throws NotLoggedInException, ContextClosedException {
    checkLogin();
    checkOpen();
    Context context = getContext();
    OpenStackContext osContext = (OpenStackContext) context;
    nova = osContext.getNovaConnector();
    ((OpenStackContext) context).refreshIfStale(nova);
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext)

Example 28 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackVolumeService method getSnapshot.

/**
 * Returns information about the snapshot with the indicated id, if it exists.
 *
 * @param id
 *            The id of the snapshot that we want to find information about
 * @return The snapshot if it exists
 * @throws ZoneException
 *             - If the snapshot cannot be listed, or the snapshot does not exist
 * @see com.att.cdp.zones.VolumeService#getSnapshot(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Snapshot getSnapshot(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SNAPSHOT, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.Snapshot snapshot = nova.getClient().snapshots().show(id).execute();
        if (snapshot == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Snapshot", id, context.getProvider().getName()));
        }
        return new OpenStackSnapshot(context, snapshot);
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    // for the compiler
    return null;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackSnapshot(com.att.cdp.openstack.model.OpenStackSnapshot) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 29 with Context

use of com.att.cdp.zones.Context 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;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackTemplate(com.att.cdp.openstack.model.OpenStackTemplate) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) 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 30 with Context

use of com.att.cdp.zones.Context in project AJSC by att.

the class OpenStackComputeService method getServers.

/**
 * Obtain a list of servers from the compute service.
 *
 * @return The list of servers that are defined.
 * @throws ZoneException
 *             - If any of the following conditions are true:
 *             <ul>
 *             <li>the user has not successfully logged in to the provider</li>
 *             <li>the context has been closed and this service is requested</li>
 *             <li>the current user does not have the rights to perform this operation</li>
 *             <li>the user and/or credentials are not valid</li>
 *             </ul>
 * @see com.att.cdp.zones.ComputeService#getServers()
 */
@Override
public List<Server> getServers() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Server> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Servers servers = nova.getClient().servers().list(true).execute();
        for (com.woorea.openstack.nova.model.Server s : servers.getList()) {
            list.add(new OpenStackServer(context, s));
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
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) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) OpenStackServer(com.att.cdp.openstack.model.OpenStackServer) ArrayList(java.util.ArrayList) Servers(com.woorea.openstack.nova.model.Servers)

Aggregations

Context (com.att.cdp.zones.Context)248 OpenStackContext (com.att.cdp.openstack.OpenStackContext)167 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)140 ArrayList (java.util.ArrayList)55 Ignore (org.junit.Ignore)50 Test (org.junit.Test)47 Quantum (com.woorea.openstack.quantum.Quantum)35 ZoneException (com.att.cdp.exceptions.ZoneException)30 NetworkService (com.att.cdp.zones.NetworkService)24 Server (com.att.cdp.zones.model.Server)22 ComputeService (com.att.cdp.zones.ComputeService)21 Network (com.att.cdp.zones.model.Network)19 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)18 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 Subnet (com.att.cdp.zones.model.Subnet)15 Port (com.att.cdp.zones.model.Port)14 Snapshot (com.att.cdp.zones.model.Snapshot)12 Volume (com.att.cdp.zones.model.Volume)11 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10