use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class VirtualArrayService method getVirtualArrayStoragePorts.
/**
* Returns the storage ports for the VirtualArray with the passed id. When
* the VirtualArray has been explicitly assigned to one or more storage
* ports, this API will return the ids of those storage ports. VirtualArrays
* can be explicitly assigned to storage ports when a storage port is
* created or later by modifying the storage port after it has been created.
* <p>
* Whether or not a VirtualArray has been explicitly assigned to any storage ports the VirtualArray may still have implicit associations
* with one or more storage port due to the VirtualArray's network connectivity. That is, a network resides in a VirtualArray and may
* contain storage ports. This implies that these storage ports reside in the VirtualArray. If the VirtualArray has no explicit storage
* port assignments, but does have implicit associations, the API will instead return those storage ports implicitly associated.
* <p>
* The API provides the ability to force the return of the list of storage ports implicitly associated with the VirtualArray using the
* request parameter "network_connectivity". Passing this parameter with a value of "true" will return the ids of the storage ports
* implicitly associated with the VirtualArray as described.
*
* @param id the URN of a ViPR VirtualArray.
* @param useNetworkConnectivity true to use the network connectivity to
* get the list of storage ports implicitly connected to the
* VirtualArray.
*
* @brief List VirtualArray storage ports
* @return The ids of the storage ports associated with the VirtualArray.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-ports")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public StoragePortList getVirtualArrayStoragePorts(@PathParam("id") URI id, @QueryParam("network_connectivity") boolean useNetworkConnectivity) {
// Get and validate the varray with the passed id.
ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
ArgValidator.checkEntity(varray, id, isIdEmbeddedInURL(id));
// Query the database for the storage ports associated with the
// VirtualArray. If the request is for storage ports whose
// association with the VirtualArray is implicit through network
// connectivity, then return only these storage ports. Otherwise,
// the result is for storage ports explicitly assigned to the
// VirtualArray.
URIQueryResultList storagePortURIs = new URIQueryResultList();
if (useNetworkConnectivity) {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getImplicitVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
} else {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
}
// Create and return the result.
StoragePortList storagePorts = new StoragePortList();
for (URI uri : storagePortURIs) {
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, uri);
if ((storagePort != null) && (RegistrationStatus.REGISTERED.toString().equals(storagePort.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(storagePort.getDiscoveryStatus())) {
storagePorts.getPorts().add(toNamedRelatedResource(storagePort, storagePort.getNativeGuid()));
}
}
return storagePorts;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class VirtualArrayService method getAvailableAttributes.
/**
* Finds the available attributes & its values in a varray. Ex: In a
* varray, if a system supports raid_levels such as RAID1, RAID2 then
* this API call provides the supported information.
*
* @param id the URN of a ViPR VirtualArray.
* @brief List available attributes for VirtualArray
* @return List available attributes for VirtualArray
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/available-attributes")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public AttributeList getAvailableAttributes(@PathParam("id") URI id) {
// Get and validate the varray with the passed id.
ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
_log.info("Finding the available attributes for varray: {}", id);
AttributeList list = new AttributeList();
list.setVArrayId(id);
ObjectLocalCache cache = new ObjectLocalCache(_dbClient);
List<StoragePool> pools = getVirtualArrayPools(Arrays.asList(id), cache).get(id);
Map<String, Set<String>> availableAttrs = _matcherFramework.getAvailableAttributes(id, pools, cache, AttributeMatcher.VPOOL_MATCHERS);
cache.clearCache();
for (Map.Entry<String, Set<String>> entry : availableAttrs.entrySet()) {
list.getAttributes().add(new VirtualPoolAvailableAttributesResourceRep(entry.getKey(), entry.getValue()));
}
return list;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class VirtualArrayService method getVirtualArrayList.
/**
* List VirtualArrays in zone the user is authorized to see
*
* @brief List VirtualArrays in zone
* @return List of VirtualArrays
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VirtualArrayList getVirtualArrayList(@DefaultValue("") @QueryParam(VDC_ID_QUERY_PARAM) String shortVdcId, @DefaultValue("") @QueryParam(TENANT_ID_QUERY_PARAM) String tenantId) {
_geoHelper.verifyVdcId(shortVdcId);
VirtualArrayList list = new VirtualArrayList();
TenantOrg tenant_input = null;
// if input tenant is not empty, but user have no access to it, return empty list.
if (!StringUtils.isEmpty(tenantId)) {
tenant_input = getTenantIfHaveAccess(tenantId);
if (tenant_input == null) {
return list;
}
}
List<VirtualArray> nhObjList = Collections.emptyList();
if (_geoHelper.isLocalVdcId(shortVdcId)) {
_log.debug("retrieving virtual arrays via dbclient");
final List<URI> ids = _dbClient.queryByType(VirtualArray.class, true);
nhObjList = _dbClient.queryObject(VirtualArray.class, ids);
} else {
_log.debug("retrieving virtual arrays via geoclient");
try {
GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
final List<URI> ids = Lists.newArrayList(geoClient.queryByType(VirtualArray.class, true));
nhObjList = Lists.newArrayList(geoClient.queryObjects(VirtualArray.class, ids));
} catch (Exception ex) {
// TODO: revisit this exception
_log.error("error retrieving virtual arrays", ex);
throw APIException.internalServerErrors.genericApisvcError("error retrieving virtual arrays", ex);
}
}
StorageOSUser user = getUserFromContext();
// else only return the list, which input tenant has access.
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
for (VirtualArray nh : nhObjList) {
if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), nh)) {
list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, nh.getId(), nh.getLabel()));
}
}
} else {
// otherwise, filter by only authorized to use
URI tenant = null;
if (tenant_input == null) {
tenant = URI.create(user.getTenantId());
} else {
tenant = tenant_input.getId();
}
Set<VirtualArray> varraySet = new HashSet<VirtualArray>();
for (VirtualArray virtualArray : nhObjList) {
if (_permissionsHelper.tenantHasUsageACL(tenant, virtualArray)) {
varraySet.add(virtualArray);
}
}
// if no tenant specified in request, also adding varrays which sub-tenants of the user have access to.
if (tenant_input == null) {
List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
for (VirtualArray virtualArray : nhObjList) {
if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualArray)) {
varraySet.add(virtualArray);
}
}
}
for (VirtualArray virtualArray : varraySet) {
list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, virtualArray.getId(), virtualArray.getLabel()));
}
}
return list;
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class VirtualArrayService method updateVirtualArray.
/**
* @brief Update VirtualArray
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/{id}")
public VirtualArrayRestRep updateVirtualArray(@PathParam("id") URI id, VirtualArrayUpdateParam param) {
VirtualArray varray = queryResource(id);
if (param.getLabel() != null && !param.getLabel().isEmpty()) {
if (!varray.getLabel().equalsIgnoreCase(param.getLabel())) {
// check for active VirtualArray with same name
checkDuplicateLabel(VirtualArray.class, param.getLabel());
}
varray.setLabel(param.getLabel());
}
if (param.getBlockSettings().getAutoSanZoning() != null) {
varray.setAutoSanZoning(param.getBlockSettings().getAutoSanZoning());
}
if (param.getObjectSettings().getProtectionType() != null) {
varray.setProtectionType(param.getObjectSettings().getProtectionType());
}
_dbClient.persistObject(varray);
auditOp(OperationTypeEnum.UPDATE_VARRAY, true, null, id.toString(), param.getLabel(), varray.getAutoSanZoning().toString());
return map(varray);
}
use of com.emc.storageos.db.client.model.VirtualArray in project coprhd-controller by CoprHD.
the class VirtualArrayService method getOtherSearchResults.
/**
* Finds the virtual arrays for the initiator port with the passed
* identifier and returns the id, name, and self link for those virtual
* arrays. This API only supports fiber channel and iSCSI initiator ports,
* and the passed port identifier must be the WWN or IQN of the port.
*
* Note that in order for an initiator to be associated with any virtual,
* arrays it must be in an active network. The virtual arrays for the passed
* initiator are those active virtual arrays associated with the storage
* ports in the initiator's active network. If the initiator is not in a
* network, an empty list is returned.
*
* parameter: 'initiator_port' The identifier of the initiator port.
*
* @param parameters The search parameters.
* @param authorized Whether or not the caller is authorized.
*
* @return The search results specifying the virtual arrays for the
* initiator identified in the passed search parameters.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
String[] searchCriteria = { SEARCH_INITIATOR_PORT, SEARCH_HOST, SEARCH_CLUSTER };
validateSearchParameters(parameters, searchCriteria);
Set<String> varrayIds = new HashSet<String>();
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
if (entry.getKey().equals(SEARCH_INITIATOR_PORT)) {
String initiatorId = parameters.get(SEARCH_INITIATOR_PORT).get(0);
// Validate the user passed a value for the initiator port.
ArgValidator.checkFieldNotEmpty(initiatorId, SEARCH_INITIATOR_PORT);
// Validate the format of the passed initiator port.
if (!EndpointUtility.isValidEndpoint(initiatorId, EndpointType.ANY)) {
throw APIException.badRequests.initiatorPortNotValid();
}
_log.info("Searching for virtual arrays for initiator {}", initiatorId);
varrayIds.addAll(ConnectivityUtil.getInitiatorVarrays(initiatorId, _dbClient));
break;
} else if (entry.getKey().equals(SEARCH_HOST)) {
// find and validate host
String hostId = parameters.get(SEARCH_HOST).get(0);
URI hostUri = URI.create(hostId);
ArgValidator.checkFieldNotEmpty(hostId, SEARCH_HOST);
Host host = queryObject(Host.class, hostUri, false);
verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
_log.info("looking for virtual arrays connected to host " + host.getHostName());
varrayIds.addAll(getVarraysForHost(hostUri));
break;
} else if (entry.getKey().equals(SEARCH_CLUSTER)) {
// find and validate cluster
String clusterId = parameters.get(SEARCH_CLUSTER).get(0);
URI clusterUri = URI.create(clusterId);
ArgValidator.checkFieldNotEmpty(clusterId, SEARCH_CLUSTER);
Cluster cluster = queryObject(Cluster.class, clusterUri, false);
verifyAuthorizedInTenantOrg(cluster.getTenant(), getUserFromContext());
_log.info("looking for virtual arrays connected to cluster " + cluster.getLabel());
List<Set<String>> hostVarraySets = new ArrayList<Set<String>>();
List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(clusterUri, Host.class, "label", "cluster");
for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
Set<String> hostVarrays = getVarraysForHost(dataObject.getId());
hostVarraySets.add(hostVarrays);
}
boolean first = true;
for (Set<String> varrays : hostVarraySets) {
if (first) {
varrayIds.addAll(varrays);
first = false;
} else {
varrayIds.retainAll(varrays);
}
}
break;
}
}
// For each virtual array in the set create a search result
// and add it to the search results list.
List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
if (!varrayIds.isEmpty()) {
for (String varrayId : varrayIds) {
URI varrayURI = URI.create(varrayId);
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayURI);
// Filter out those that are inactive or not accessible to the user.
if (varray == null || varray.getInactive()) {
_log.info("Could not find virtual array {} in the database, or " + "the virtual array is inactive", varrayURI);
continue;
}
if (!authorized) {
if (!_permissionsHelper.tenantHasUsageACL(URI.create(getUserFromContext().getTenantId()), varray)) {
_log.info("Virtual array {} is not accessible.", varrayURI);
continue;
}
}
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), varrayURI));
SearchResultResourceRep searchResult = new SearchResultResourceRep(varrayURI, selfLink, varray.getLabel());
searchResultList.add(searchResult);
}
}
result.setResource(searchResultList);
return result;
}
Aggregations