use of com.emc.storageos.db.client.model.VirtualNAS in project coprhd-controller by CoprHD.
the class ProjectService method validateVNasServers.
/**
* Validate VNAS Servers before assign to a project
*
* @param project to which VANS servers will be assigned
* @param param Assign virtual NAS server parameters
* @param error message
* @brief Validate VNAS Servers
* @return List of valid NAS servers
* @throws BadRequestException
*/
public StringSet validateVNasServers(Project project, VirtualNasParam param, StringBuilder errorMsg) {
Set<String> vNasIds = param.getVnasServers();
StringSet validNas = new StringSet();
boolean shareVNASWithMultipleProjects = Boolean.valueOf(customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.SHARE_VNAS_WITH_MULTIPLE_PROJECTS, "global", null));
_log.info("Can vNAS be shared with multiple projects? : {}", shareVNASWithMultipleProjects);
if (vNasIds != null && !vNasIds.isEmpty() && project != null) {
// Get list of domains associated with the project
Set<String> projectDomains = ProjectUtility.getDomainsOfProject(_permissionsHelper, project);
for (String id : vNasIds) {
if (project.getAssignedVNasServers().contains(id)) {
continue;
}
URI vnasURI = URI.create(id);
VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
// Validate the VNAS is assigned to project!!!
if (!shareVNASWithMultipleProjects && !vnas.isNotAssignedToProject()) {
errorMsg.append(" vNas: " + vnas.getNasName() + " is already associated to a project.");
_log.error(errorMsg.toString());
continue;
}
// Validate the VNAS is in Discovery state -VISIBLE!!!
if (!DiscoveryStatus.VISIBLE.name().equals(vnas.getDiscoveryStatus())) {
errorMsg.append(" vNas " + vnas.getNasName() + " is not in Discovery-VISIBLE state ");
_log.error(errorMsg.toString());
continue;
}
// Validate the VNAS state should be in loaded state !!!
if (!vnas.getVNasState().equalsIgnoreCase(VirtualNasState.LOADED.getNasState())) {
errorMsg.append(" vNas " + vnas.getNasName() + " is not in Loaded state");
_log.error(errorMsg.toString());
continue;
}
// Get list of domains associated with a VNAS server and validate with project's domain
boolean domainMatched = ProjectUtility.doesProjectDomainMatchesWithVNASDomain(projectDomains, vnas);
if (!domainMatched) {
errorMsg.append(" vNas " + vnas.getNasName() + " domain is not matched with project domain");
_log.error(errorMsg.toString());
continue;
}
if (!shareVNASWithMultipleProjects) {
/*
* Get list of file systems and associated project of VNAS server and validate with Project
* If the FS is on a vNAS associated with a project, then validation fails
*/
URIQueryResultList fsList = new URIQueryResultList();
boolean projectMatched = true;
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, vnas.getStorageDeviceURI());
for (String storagePort : vnas.getStoragePorts()) {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortFileshareConstraint(URI.create(storagePort)), fsList);
Iterator<URI> fsItr = fsList.iterator();
while (fsItr.hasNext()) {
FileShare fileShare = _dbClient.queryObject(FileShare.class, fsItr.next());
if (fileShare != null && !fileShare.getInactive()) {
// if fs contain vNAS uri, then compare uri of vNAS assgined to project
if (fileShare.getVirtualNAS() != null && 0 == fileShare.getVirtualNAS().compareTo(vnas.getId())) {
_log.debug("Validation of assigned vNAS URI: {} and file system path : {} ", fileShare.getVirtualNAS(), fileShare.getPath());
if (!fileShare.getProject().getURI().toString().equals(project.getId().toString())) {
projectMatched = false;
break;
}
} else {
// for isilon, if fs don't have vNAS uri, compare fspath with base path of AZ
if (storageSystem.getSystemType().equals(StorageSystem.Type.isilon.name())) {
if (fileShare.getPath().startsWith(vnas.getBaseDirPath() + "/") == false) {
continue;
}
}
_log.debug("Validation of assigned vNAS base path {} and file path : {} ", vnas.getBaseDirPath(), fileShare.getPath());
if (!fileShare.getProject().getURI().toString().equals(project.getId().toString())) {
projectMatched = false;
break;
}
}
}
}
if (!projectMatched) {
break;
}
}
if (!projectMatched) {
errorMsg.append(" vNas " + vnas.getNasName() + " has file systems belongs to other project");
_log.error(errorMsg.toString());
continue;
}
}
validNas.add(id);
}
} else {
throw APIException.badRequests.invalidEntryForProjectVNAS();
}
return validNas;
}
use of com.emc.storageos.db.client.model.VirtualNAS in project coprhd-controller by CoprHD.
the class VirtualNasService method queryResource.
@Override
protected VirtualNAS queryResource(URI id) {
ArgValidator.checkUri(id);
VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, id);
ArgValidator.checkEntity(vNas, id, isIdEmbeddedInURL(id));
return vNas;
}
use of com.emc.storageos.db.client.model.VirtualNAS in project coprhd-controller by CoprHD.
the class VirtualNasService method getVirtualNasServer.
/**
* Gets the details of virtual NAS.
*
* @param id the URN of a ViPR virtual NAS.
*
* @brief Show virtual NAS
* @return A VirtualNASRestRep reference specifying the data for the
* virtual NAS with the passed id.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public VirtualNASRestRep getVirtualNasServer(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, VirtualNAS.class, "id");
VirtualNAS vNas = queryResource(id);
return MapVirtualNas.getInstance(_dbClient).toVirtualNasRestRep(vNas);
}
use of com.emc.storageos.db.client.model.VirtualNAS in project coprhd-controller by CoprHD.
the class VirtualNasService method queryRegisteredResource.
/**
* Gets the virtual NAS with the passed id from the database.
*
* @param id the URN of a ViPR virtual NAS.
* @return A reference to the registered VirtualNAS.
* @throws BadRequestException When the vNAS is not registered.
*/
protected VirtualNAS queryRegisteredResource(URI id) {
ArgValidator.checkUri(id);
VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, id);
ArgValidator.checkEntity(vNas, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(vNas.getRegistrationStatus())) {
throw APIException.badRequests.resourceNotRegistered(VirtualNAS.class.getSimpleName(), id);
}
return vNas;
}
use of com.emc.storageos.db.client.model.VirtualNAS in project coprhd-controller by CoprHD.
the class StoragePortService method getVirtualNasForStoragePort.
/**
* It return VirtualNAS for given StoragePort
*
* @param sp A reference to the storage port.
* @return VirtualNAS for a storage Port
*/
private VirtualNAS getVirtualNasForStoragePort(StoragePort sp) {
URIQueryResultList vNasUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualNASContainStoragePortConstraint(sp.getId()), vNasUriList);
Iterator<URI> vNasIter = vNasUriList.iterator();
while (vNasIter.hasNext()) {
VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, vNasIter.next());
if (vNas != null && !vNas.getInactive()) {
return vNas;
}
}
return null;
}
Aggregations