use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class RPDeviceController method updateProtectionSet.
/**
* Update a protection set in the database that corresponds to the CG.
*
* BH Note: Currently this only supports adding to the protection set. We may eventually
* want to support removal as well.
*
* @param params
* CG params object
* @throws InternalException
*/
private ProtectionSet updateProtectionSet(ProtectionSet protectionSet, CGRequestParams params) throws InternalException {
StringSet protectionSetVolumes = new StringSet();
_log.info(String.format("Updating protection set [%s]", protectionSet.getLabel()));
// Keep a list of all volumes that were created. This will be used to ensure we do not
// consider volumes from this create request when setting access state and link status
// based on existing volumes in the CG.
List<URI> volumesInCreateRequest = new ArrayList<URI>();
for (CreateRSetParams rset : params.getRsets()) {
for (CreateVolumeParams volume : rset.getVolumes()) {
volumesInCreateRequest.add(volume.getVolumeURI());
}
}
// protection set
for (CreateRSetParams rset : params.getRsets()) {
for (CreateVolumeParams volume : rset.getVolumes()) {
if (protectionSet.getVolumes() != null && protectionSet.getVolumes().contains(volume.getVolumeURI().toString())) {
// Protection Set already has a reference to this volume, continue.
continue;
} else {
Volume vol = _dbClient.queryObject(Volume.class, volume.getVolumeURI());
// hasn't already been set.
if (protectionSet.getProject() == null) {
protectionSet.setProject(vol.getProject().getURI());
}
vol.setProtectionSet(new NamedURI(protectionSet.getId(), protectionSet.getLabel()));
if (vol.checkPersonality(Volume.PersonalityTypes.SOURCE.toString())) {
vol.setAccessState(Volume.VolumeAccessState.READWRITE.name());
vol.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
// Check the CG for an existing source volume. If the CG has an existing
// source volume, we want to mirror the access state and link status for
// all new source volumes.
List<Volume> existingCgSourceVolumes = RPHelper.getCgSourceVolumes(vol.getConsistencyGroup(), _dbClient);
if (existingCgSourceVolumes != null) {
for (Volume sourceVolume : existingCgSourceVolumes) {
if (!vol.getId().equals(sourceVolume.getId()) && !volumesInCreateRequest.contains(sourceVolume.getId())) {
_log.info(String.format("Updating source volume %s. Setting access state = %s, link status = %s. Based on existing CG source volume %s.", vol.getId(), sourceVolume.getAccessState(), sourceVolume.getLinkStatus(), sourceVolume.getId()));
vol.setAccessState(sourceVolume.getAccessState());
vol.setLinkStatus(sourceVolume.getLinkStatus());
break;
}
}
}
} else if (vol.checkPersonality(Volume.PersonalityTypes.TARGET.toString())) {
vol.setAccessState(Volume.VolumeAccessState.NOT_READY.name());
vol.setLinkStatus(Volume.LinkStatus.IN_SYNC.name());
// Check the CG for an existing target volume corresponding to the same RP copy
// as this volume and mirror its access state and link statues. If the target
// copy happens to be in direct access mode, it's important that the new volume
// be marked FAILED_OVER and READWRITE.
List<Volume> existingCgTargets = RPHelper.getTargetVolumesForVarray(_dbClient, vol.getConsistencyGroup(), vol.getVirtualArray());
if (existingCgTargets != null && vol.getRpCopyName() != null) {
for (Volume targetVolume : existingCgTargets) {
// lets use it to set the access state and link status values.
if (!vol.getId().equals(targetVolume.getId()) && !volumesInCreateRequest.contains(targetVolume.getId()) && vol.getRpCopyName().equalsIgnoreCase(targetVolume.getRpCopyName())) {
_log.info(String.format("Updating volume %s. Setting access state = %s, link status = %s. Based on existing CG target volume %s.", vol.getId(), targetVolume.getAccessState(), targetVolume.getLinkStatus(), targetVolume.getId()));
vol.setAccessState(targetVolume.getAccessState());
vol.setLinkStatus(targetVolume.getLinkStatus());
break;
}
}
}
}
_dbClient.updateObject(vol);
protectionSetVolumes.add(vol.getId().toString());
_log.info(String.format("Adding volume [%s] to protection set [%s]", vol.getLabel(), protectionSet.getLabel()));
}
}
}
// protection set
for (CreateCopyParams copy : params.getCopies()) {
for (CreateVolumeParams volume : copy.getJournals()) {
if (protectionSet.getVolumes() != null && protectionSet.getVolumes().contains(volume.getVolumeURI().toString())) {
// Protection Set already has a reference to this volume, continue.
continue;
} else {
Volume vol = _dbClient.queryObject(Volume.class, volume.getVolumeURI());
vol.setProtectionSet(new NamedURI(protectionSet.getId(), protectionSet.getLabel()));
vol.setAccessState(Volume.VolumeAccessState.NOT_READY.name());
_dbClient.updateObject(vol);
protectionSetVolumes.add(vol.getId().toString());
_log.info(String.format("Adding volume [%s] to protection set [%s]", vol.getLabel(), protectionSet.getLabel()));
}
}
}
if (protectionSet.getVolumes() == null) {
protectionSet.setVolumes(protectionSetVolumes);
} else {
protectionSet.getVolumes().addAll(protectionSetVolumes);
}
_dbClient.updateObject(protectionSet);
return protectionSet;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class SRDFDeviceController method createCGSRDFVolumes.
protected void createCGSRDFVolumes(Workflow workflow, String waitFor, List<VolumeDescriptor> sourceDescriptors, List<VolumeDescriptor> targetDescriptors, Map<URI, Volume> uriVolumeMap) {
RemoteDirectorGroup group = getRAGroup(targetDescriptors, uriVolumeMap);
StorageSystem system = dbClient.queryObject(StorageSystem.class, group.getSourceStorageSystemUri());
StorageSystem targetSystem = dbClient.queryObject(StorageSystem.class, group.getRemoteStorageSystemUri());
// finding actual volumes from Provider
Set<String> volumes = findVolumesPartOfRDFGroups(system, group);
if (group.getVolumes() == null) {
group.setVolumes(new StringSet());
}
/*
* Check the following 2 conditions.
* 1. If there are no volumes in RDFGroup on Array & volumes in RDFGroup in ViPR DB.
* 2. If there are volumes in RDFGroup on Array & no volumes in RDFGroup in ViPR DB.
*/
if ((group.getVolumes().isEmpty() && !volumes.isEmpty()) || (!group.getVolumes().isEmpty() && volumes.isEmpty())) {
// throw Exception rediscover source and target arrays.
log.warn("RDF Group {} out of sync with Array", group.getNativeGuid());
List<URI> sourceURIs = VolumeDescriptor.getVolumeURIs(sourceDescriptors);
List<URI> targetURIs = VolumeDescriptor.getVolumeURIs(targetDescriptors);
URI vpoolChangeUri = getVirtualPoolChangeVolume(sourceDescriptors);
for (URI sourceUri : sourceURIs) {
Volume sourceVolume = dbClient.queryObject(Volume.class, sourceUri);
if (null != sourceVolume) {
log.info("Clearing source volume {}-->{}", sourceVolume.getNativeGuid(), sourceVolume.getId());
if (null == vpoolChangeUri) {
// clear everything if not vpool change
sourceVolume.setPersonality(NullColumnValueGetter.getNullStr());
sourceVolume.setAccessState(Volume.VolumeAccessState.READWRITE.name());
sourceVolume.setInactive(true);
sourceVolume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
}
if (null != sourceVolume.getSrdfTargets()) {
sourceVolume.getSrdfTargets().clear();
}
dbClient.updateObject(sourceVolume);
}
}
for (URI targetUri : targetURIs) {
Volume targetVolume = dbClient.queryObject(Volume.class, targetUri);
if (null != targetVolume) {
log.info("Clearing target volume {}-->{}", targetVolume.getNativeGuid(), targetVolume.getId());
targetVolume.setPersonality(NullColumnValueGetter.getNullStr());
targetVolume.setAccessState(Volume.VolumeAccessState.READWRITE.name());
targetVolume.setSrdfParent(new NamedURI(NullColumnValueGetter.getNullURI(), NullColumnValueGetter.getNullStr()));
targetVolume.setSrdfCopyMode(NullColumnValueGetter.getNullStr());
targetVolume.setSrdfGroup(NullColumnValueGetter.getNullURI());
targetVolume.setConsistencyGroup(NullColumnValueGetter.getNullURI());
targetVolume.setInactive(true);
dbClient.updateObject(targetVolume);
}
}
throw DeviceControllerException.exceptions.srdfAsyncStepCreationfailed(group.getNativeGuid());
}
group.getVolumes().replace(volumes);
dbClient.updateObject(group);
if (volumes.isEmpty() && SupportedCopyModes.ALL.toString().equalsIgnoreCase(group.getSupportedCopyMode())) {
log.info("RA Group {} was empty", group.getId());
waitFor = createSrdfCgPairStepsOnEmptyGroup(sourceDescriptors, targetDescriptors, group, waitFor, workflow);
} else {
log.info("RA Group {} not empty", group.getId());
waitFor = createSrdfCGPairStepsOnPopulatedGroup(sourceDescriptors, group, uriVolumeMap, waitFor, workflow);
}
// Generate workflow step to refresh target system after CG creation.
if (null != system) {
waitFor = addStepToRefreshSystem(CREATE_SRDF_MIRRORS_STEP_GROUP, system, null, waitFor, workflow);
}
if (null != targetSystem) {
waitFor = addStepToRefreshSystem(CREATE_SRDF_MIRRORS_STEP_GROUP, targetSystem, null, waitFor, workflow);
}
// Refresh target volume properties
Mode SRDFMode = getSRDFMode(sourceDescriptors, uriVolumeMap);
if (Mode.ACTIVE.equals(SRDFMode)) {
refreshVolumeProperties(targetDescriptors, targetSystem, waitFor, workflow);
}
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class ExportUtils method createVplexExportGroup.
/**
* Create an ExportGroup.
*
* @param vplex -- VPLEX StorageSystem
* @param array -- Array StorageSystem
* @param initiators -- Collection<Initiator> representing VPLEX back-end ports.
* @param virtualArrayURI
* @param projectURI
* @param tenantURI
* @param numPaths Value of maxPaths to be put in ExportGroup
* @param exportMask IFF non-null, will add the exportMask to the Export Group.
* @return newly created ExportGroup persisted in DB.
*/
public static ExportGroup createVplexExportGroup(DbClient dbClient, StorageSystem vplex, StorageSystem array, Collection<Initiator> initiators, URI virtualArrayURI, URI projectURI, URI tenantURI, int numPaths, ExportMask exportMask) {
String groupName = getExportGroupName(vplex, array) + "_" + UUID.randomUUID().toString().substring(28);
if (exportMask != null) {
String arrayName = array.getSystemType().replace("block", "") + array.getSerialNumber().substring(array.getSerialNumber().length() - 4);
groupName = exportMask.getMaskName() + "_" + arrayName;
}
// No existing group has the mask, let's create one.
ExportGroup exportGroup = new ExportGroup();
exportGroup.setId(URIUtil.createId(ExportGroup.class));
exportGroup.setLabel(groupName);
exportGroup.setProject(new NamedURI(projectURI, exportGroup.getLabel()));
exportGroup.setVirtualArray(vplex.getVirtualArray());
exportGroup.setTenant(new NamedURI(tenantURI, exportGroup.getLabel()));
exportGroup.setGeneratedName(groupName);
exportGroup.setVolumes(new StringMap());
exportGroup.setOpStatus(new OpStatusMap());
exportGroup.setVirtualArray(virtualArrayURI);
exportGroup.setNumPaths(numPaths);
// Add the initiators into the ExportGroup.
for (Initiator initiator : initiators) {
exportGroup.addInitiator(initiator);
}
// If we have an Export Mask, add it into the Export Group.
if (exportMask != null) {
exportGroup.addExportMask(exportMask.getId());
}
// Persist the ExportGroup
dbClient.createObject(exportGroup);
_log.info(String.format("Returning new ExportGroup %s", exportGroup.getLabel()));
return exportGroup;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class TaskService method getOtherSearchResults.
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults searchResults = new SearchResults();
Set<URI> tenantIds = getTenantIdsFromParams(parameters);
// Resource Query
if (parameters.containsKey(RESOURCE_QUERY_PARAM)) {
URI resourceId = URI.create(parameters.get(RESOURCE_QUERY_PARAM).get(0));
List<NamedURI> tasks = TaskUtils.findResourceTaskIds(_dbClient, resourceId);
if (!tasks.isEmpty()) {
// All the tasks will have the same TenantID as the Resource
Task task = queryResource(tasks.get(0).getURI());
verifyUserHasAccessToTenants(Collections.singletonList(task.getTenant()));
}
searchResults.getResource().addAll(toSearchResults(tasks));
} else if (parameters.containsKey(STATE_PARAM)) {
// Search by task state
String state = getStringParam(STATE_PARAM, parameters);
if (state != null) {
for (URI tenant : tenantIds) {
TaskUtils.ObjectQueryResult<Task> taskResult = TaskUtils.findTenantTasks(_dbClient, tenant);
while (taskResult.hasNext()) {
Task task = taskResult.next();
if (task.getStatus().equals(state)) {
searchResults.getResource().add(toSearchResult(task.getId()));
}
}
}
}
}
return searchResults;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class TenantsService method createProject.
/**
* Worker method for create project. Allows external requests (REST) as well as
* internal requests that may not have a security context.
*
* @param id tenant id
* @param param project params
* @param owner name of owner of the request
* @param ownerTenantId tenant id of the owner
* @return project details
*/
public ProjectElement createProject(URI id, ProjectParam param, String owner, String ownerTenantId) {
TenantOrg tenant = getTenantById(id, true);
if (param.getName() != null && !param.getName().isEmpty()) {
checkForDuplicateName(param.getName(), Project.class, id, "tenantOrg", _dbClient);
}
Project project = new Project();
project.setId(URIUtil.createId(Project.class));
project.setLabel(param.getName());
project.setTenantOrg(new NamedURI(tenant.getId(), project.getLabel()));
project.setOwner(owner);
// set owner acl
project.addAcl(new PermissionsKey(PermissionsKey.Type.SID, owner, ownerTenantId).toString(), ACL.OWN.toString());
_dbClient.createObject(project);
recordTenantEvent(OperationTypeEnum.CREATE_PROJECT, tenant.getId(), project.getId());
return new ProjectElement(project.getId(), toLink(ResourceTypeEnum.PROJECT, project.getId()), project.getLabel());
}
Aggregations