Search in sources :

Example 1 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackStackService method getStacks.

/**
 * Obtains a list (unfiltered) of all stacks that exist on the provider and returns them to the caller.
 *
 * @return A list of all stacks that exist. Note that the list may be empty.
 * @throws ZoneException
 *             - If the context is closed, a login has not occurred, or an error happened trying to contact the
 *             provider.
 * @see com.att.cdp.zones.StackService#getStacks()
 */
@Override
public List<Stack> getStacks() throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SERVICE, "Orchestration");
    RequestState.put(RequestState.SERVICE_URL, connector.getEndpoint());
    ArrayList<Stack> list = new ArrayList<>();
    Heat heat = connector.getClient();
    StackResource resource = heat.getStacks();
    try {
        /*
             * Get a list of stacks, then call byName api for each one to get the detail for the stack.
             */
        Stacks osStacks = resource.list().execute();
        if (osStacks != null) {
            for (com.woorea.openstack.heat.model.Stack osStack : osStacks) {
                list.add(getStack(osStack.getStackName(), osStack.getId()));
            }
        }
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) Heat(com.woorea.openstack.heat.Heat) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList) Stacks(com.woorea.openstack.heat.model.Stacks) Stack(com.att.cdp.zones.model.Stack) AbstractStack(com.att.cdp.zones.spi.AbstractStack) OpenStackStack(com.att.cdp.openstack.model.OpenStackStack) StackResource(com.woorea.openstack.heat.StackResource)

Example 2 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method getVolumes.

/**
 * Returns a list of volumes that match the supplied name
 *
 * @param name
 *            The name pattern of the volumes to be located. The name is a regular expression that is suitable for
 *            use in the Java String.matches() method.
 * @return A list (potentially empty) of all volumes that match the specified name pattern
 * @throws ZoneException
 *             - If the volume service cannot be accessed.
 * @see java.lang.String#matches(String)
 * @see com.att.cdp.zones.VolumeService#getVolumes(java.lang.String)
 */
@Override
public List<Volume> getVolumes(String name) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, name);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    ArrayList<Volume> list = new ArrayList<>();
    try {
        com.woorea.openstack.nova.model.Volumes volumes = nova.getClient().volumes().list(true).execute();
        for (com.woorea.openstack.nova.model.Volume volume : volumes) {
            if (name != null) {
                if (volume.getName() != null && volume.getName().matches(name)) {
                    list.add(new OpenStackVolume(context, volume));
                }
            } else {
                list.add(new OpenStackVolume(context, volume));
            }
        }
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
    return list;
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) Volume(com.att.cdp.zones.model.Volume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) AbstractVolume(com.att.cdp.zones.spi.AbstractVolume) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList)

Example 3 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method createVolume.

/**
 * This method is used to create a new volume using the Volume object (disconnected) as the model. When the method
 * returns, a connected model object is returned that should be used for any model navigation desired.
 *
 * @param template
 *            The template of the volume to create. This must contain at least a name and size. Other information
 *            will be supplied if not present. Any ID is ignored, and the ID of the created volume is returned in
 *            the connected volume object returned to the caller.
 * @return A Volume object that is connected to the service context and can be used to navigate the model.
 * @throws ZoneException
 *             - If the volume cannot be created for some reason.
 * @see com.att.cdp.zones.VolumeService#createVolume(com.att.cdp.zones.model.Volume)
 */
@SuppressWarnings("nls")
@Override
public Volume createVolume(Volume template) throws ZoneException {
    checkArg(template, "template");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, template.getName());
    RequestState.put(RequestState.SIZE, template.getSize());
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.VolumeForCreate newVolume = new com.woorea.openstack.nova.model.VolumeForCreate();
        HashMap<String, String> dictionary = new HashMap<>();
        dictionary.put("name", "name");
        dictionary.put("description", "description");
        dictionary.put("size", "size");
        dictionary.put("snapshotId", "snapshotId");
        dictionary.put("availabilityZone", "availabilityZone");
        ObjectMapper.map(template, newVolume, dictionary);
        OpenStackVolume volume = new OpenStackVolume(context, nova.getClient().volumes().create(newVolume).execute());
        return volume;
    } 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) HashMap(java.util.HashMap) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Example 4 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method getVolume.

/**
 * Returns information about the volume with the indicated id, if it exists.
 *
 * @param id
 *            The id of the volume that we want to find information about
 * @return The volume if it exists
 * @throws ZoneException
 *             - If the volume cannot be listed, or the volume does not exist
 * @see com.att.cdp.zones.VolumeService#getVolume(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Volume getVolume(String id) throws ZoneException {
    checkArg(id, "id");
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.VOLUME, id);
    RequestState.put(RequestState.SERVICE, "Compute");
    RequestState.put(RequestState.SERVICE_URL, nova.getEndpoint());
    try {
        com.woorea.openstack.nova.model.Volume volume = nova.getClient().volumes().show(id).execute();
        if (volume == null) {
            throw new ResourceNotFoundException(EELFResourceManager.format(OSMsg.PAL_OS_RESOURCE_NOT_FOUND, "Volume", id, context.getProvider().getName()));
        }
        return new OpenStackVolume(context, volume);
    } 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) OpenStackVolume(com.att.cdp.openstack.model.OpenStackVolume) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ResourceNotFoundException(com.att.cdp.exceptions.ResourceNotFoundException)

Example 5 with OpenStackBaseException

use of com.woorea.openstack.base.client.OpenStackBaseException in project AJSC by att.

the class OpenStackVolumeService method destroySnapshot.

/**
 * This method can be called to destroy a snapshot.
 *
 * @param id
 *            The id of the snapshot to be destroyed.
 * @throws ZoneException
 *             - If the snapshot cannot be destroyed.
 * @see com.att.cdp.zones.VolumeService#destroySnapshot(java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public void destroySnapshot(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 {
        nova.getClient().snapshots().delete(id).execute();
    } catch (OpenStackBaseException ex) {
        ExceptionMapper.mapException(ex);
    }
}
Also used : OpenStackContext(com.att.cdp.openstack.OpenStackContext) Context(com.att.cdp.zones.Context) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException)

Aggregations

OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)151 OpenStackContext (com.att.cdp.openstack.OpenStackContext)140 Context (com.att.cdp.zones.Context)140 ArrayList (java.util.ArrayList)54 Quantum (com.woorea.openstack.quantum.Quantum)36 OpenStackSnapshot (com.att.cdp.openstack.model.OpenStackSnapshot)18 ZoneException (com.att.cdp.exceptions.ZoneException)15 OpenStackServer (com.att.cdp.openstack.model.OpenStackServer)14 Server (com.att.cdp.zones.model.Server)11 ConnectedServer (com.att.cdp.zones.spi.model.ConnectedServer)11 HashMap (java.util.HashMap)11 ResourceNotFoundException (com.att.cdp.exceptions.ResourceNotFoundException)10 Snapshot (com.att.cdp.zones.model.Snapshot)10 OpenStackACL (com.att.cdp.openstack.model.OpenStackACL)8 OpenStackImage (com.att.cdp.openstack.model.OpenStackImage)8 OpenStackPort (com.att.cdp.openstack.model.OpenStackPort)8 OpenStackVolume (com.att.cdp.openstack.model.OpenStackVolume)8 OpenStackNetwork (com.att.cdp.openstack.model.OpenStackNetwork)7 Network (com.att.cdp.zones.model.Network)7 Port (com.att.cdp.zones.model.Port)7