
com.emc.vipr.client.core.ComputeSystems Maven / Gradle / Ivy
/*
* Copyright (c) 2015 EMC Corporation
* All Rights Reserved
*/
package com.emc.vipr.client.core;
import static com.emc.vipr.client.core.util.ResourceUtils.defaultList;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.UriBuilder;
import com.emc.storageos.model.BulkIdParam;
import com.emc.storageos.model.NamedRelatedResourceRep;
import com.emc.storageos.model.compute.ComputeElementListRestRep;
import com.emc.storageos.model.compute.ComputeElementRestRep;
import com.emc.storageos.model.compute.ComputeSystemBulkRep;
import com.emc.storageos.model.compute.ComputeSystemCreate;
import com.emc.storageos.model.compute.ComputeSystemList;
import com.emc.storageos.model.compute.ComputeSystemRestRep;
import com.emc.storageos.model.compute.ComputeSystemUpdate;
import com.emc.vipr.client.Task;
import com.emc.vipr.client.Tasks;
import com.emc.vipr.client.ViPRCoreClient;
import com.emc.vipr.client.core.filters.ResourceFilter;
import com.emc.vipr.client.core.impl.PathConstants;
import com.emc.vipr.client.core.util.ResourceUtils;
import com.emc.vipr.client.impl.RestClient;
/**
* Storage Systems resources.
*
* Base URL: /vdc/compute-systems
*/
public class ComputeSystems extends AbstractCoreBulkResources implements
TopLevelResources, TaskResources {
public ComputeSystems(ViPRCoreClient parent, RestClient client) {
super(parent, client, ComputeSystemRestRep.class, PathConstants.COMPUTE_SYSTEMS_URL);
}
@Override
public ComputeSystems withInactive(boolean inactive) {
return (ComputeSystems) super.withInactive(inactive);
}
@Override
protected List getBulkResources(BulkIdParam input) {
ComputeSystemBulkRep response = client.post(ComputeSystemBulkRep.class, input, getBulkUrl());
return defaultList(response.getComputeSystems());
}
@Override
public Tasks getTasks(URI id) {
return doGetTasks(id);
}
@Override
public Task getTask(URI id, URI taskId) {
return doGetTask(id, taskId);
}
/**
* Lists all compute systems.
*
* API Call: GET /vdc/compute-systems
*
* @return the list of compute system references.
*/
@Override
public List list() {
ComputeSystemList response = client.get(ComputeSystemList.class, baseUrl);
return ResourceUtils.defaultList(response.getComputeSystems());
}
/**
* Gets the list of all compute systems. This is a convenience method for: getByRefs(list()).
*
* @return the list of all compute systems.
*/
@Override
public List getAll() {
return getAll(null);
}
/**
* Gets the list of all compute systems, optionally filtering the results. This is a convenience method for:
* getByRefs(list(), filter).
*
* @param filter
* the resource filter to apply to the results as they are returned (optional).
* @return the list of all compute systems.
*/
@Override
public List getAll(ResourceFilter filter) {
List refs = list();
return getByRefs(refs, filter);
}
/**
* Begins creating a compute system.
*
* API Call: POST /vdc/compute-systems
*
* @param input
* the create configuration.
* @return a task for monitoring the progress of the operation.
*/
public Task create(ComputeSystemCreate input) {
return postTask(input, baseUrl);
}
/**
* Begins updating the given compute system by ID.
*
* API Call: PUT /vdc/compute-systems/{id}
*
* @param id
* the ID of the compute system.
* @param input
* the update configuration.
* @return a task for monitoring the progress of the operation.
*/
public Task update(URI id, ComputeSystemUpdate input) {
return putTask(input, getIdUrl(), id);
}
/**
* Begins deactivating the given compute system by ID.
*
* API Call: POST /vdc/compute-systems/{id}/deactivate
*
* @param id
* the ID of the compute system.
* @return a task for monitoring the progress of the operation.
*/
public Task deactivate(URI id) {
return doDeactivateWithTask(id);
}
/**
* Begins discovery on all compute systems.
*
* API Call: POST /vdc/compute-systems/discover
*
* @return Tasks for monitoring the progress of the operation(s).
*/
public Tasks discoverAll() {
return postTasks(baseUrl + "/discover");
}
/**
* Begins discovery on the given compute system.
*
* API Call: POST /vdc/compute-systems/{id}/discover
*
* @param id
* the ID of the compute system.
* @return a task for monitoring the progress of the operation.
*/
public Task discover(URI id) {
UriBuilder builder = client.uriBuilder(getIdUrl() + "/discover");
return postTaskURI(builder.build(id));
}
/**
* Registers the given storage system by ID.
*
* API Call: POST /vdc/storage-systems/{id}/register
*
* @param id
* the ID of the storage system.
* @return the updated storage system.
*/
public ComputeSystemRestRep register(URI id) {
return client.post(ComputeSystemRestRep.class, getIdUrl() + "/register", id);
}
/**
* De-registers the given storage system by ID.
*
* API Call: POST /vdc/storage-systems/{id}/deregister
*
* @param id
* the ID of the storage system.
* @return the updated storage system.
*/
public ComputeSystemRestRep deregister(URI id) {
return client.post(ComputeSystemRestRep.class, getIdUrl() + "/deregister", id);
}
/**
* Gets the list of Compute Elements in the given Compute System.
*
* API Call: GET /vdc/compute-systems/{id}/compute-elements
*
* @param id
* the ID of the compute system.
* @return the list of Compute Elements.
*/
public List getComputeElements(URI id) {
ComputeElementListRestRep response = client.get(ComputeElementListRestRep.class, getIdUrl() + "/compute-elements", id);
return defaultList(response.getList());
}
}