Search in sources :

Example 6 with ResourceNotFoundException

use of com.att.cdp.exceptions.ResourceNotFoundException 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;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) ArrayList(java.util.ArrayList) OpenStackRequest(com.woorea.openstack.base.client.OpenStackRequest) Roles(com.woorea.openstack.keystone.model.Roles) Role(com.woorea.openstack.keystone.model.Role) ContextConnectionException(com.att.cdp.exceptions.ContextConnectionException) Keystone(com.woorea.openstack.keystone.Keystone) ZoneException(com.att.cdp.exceptions.ZoneException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 7 with ResourceNotFoundException

use of com.att.cdp.exceptions.ResourceNotFoundException 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 8 with ResourceNotFoundException

use of com.att.cdp.exceptions.ResourceNotFoundException in project AJSC by att.

the class OpenStackSnapshotService 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.SnapshotService#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 9 with ResourceNotFoundException

use of com.att.cdp.exceptions.ResourceNotFoundException in project AJSC by att.

the class OpenStackSnapshotService 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.SnapshotService#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, "Volume");
    RequestState.put(RequestState.SERVICE_URL, cinder.getEndpoint());
    try {
        com.woorea.openstack.cinder.model.Snapshot snapshot = cinder.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)

Aggregations

ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)9 OpenStackContext (com.att.cdp.openstack.OpenStackContext)9 Context (com.att.cdp.zones.Context)9 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)8 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)4 ZoneException (com.att.cdp.exceptions.ZoneException)3 OpenStackConnectException (com.woorea.openstack.base.client.OpenStackConnectException)3 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)3 ContextClosedException (com.att.cdp.exceptions.ContextClosedException)2 InvalidRequestException (com.att.cdp.exceptions.InvalidRequestException)2 NotLoggedInException (com.att.cdp.exceptions.NotLoggedInException)2 OpenStackTemplate (com.att.cdp.openstack.model.OpenStackTemplate)2 OpenStackVolume (com.att.cdp.openstack.model.OpenStackVolume)2 ContextConnectionException (com.att.cdp.exceptions.ContextConnectionException)1 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)1 Keystone (com.woorea.openstack.keystone.Keystone)1 Role (com.woorea.openstack.keystone.model.Role)1 Roles (com.woorea.openstack.keystone.model.Roles)1 ArrayList (java.util.ArrayList)1