use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.
the class XIVRestOperationsHelper method setTag.
private void setTag(DataObject object, String scope, String label) {
if (label == null) {
// shouldn't happen
label = "";
}
ScopedLabel newScopedLabel = new ScopedLabel(scope, label);
ScopedLabelSet tagSet = object.getTag();
if (tagSet == null) {
tagSet = new ScopedLabelSet();
tagSet.add(newScopedLabel);
object.setTag(tagSet);
} else if (tagSet.contains(newScopedLabel)) {
return;
} else {
removeLabel(tagSet, scope);
tagSet.add(newScopedLabel);
}
_dbClient.persistObject(object);
}
use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.
the class XIVRestOperationsHelper method removeLabel.
private void removeLabel(ScopedLabelSet tagSet, String scope) {
ScopedLabel oldScopedLabel = null;
Iterator<ScopedLabel> itr = tagSet.iterator();
while (itr.hasNext()) {
ScopedLabel scopedLabel = itr.next();
if (scope.equals(scopedLabel.getScope())) {
oldScopedLabel = scopedLabel;
break;
}
}
if (oldScopedLabel != null) {
tagSet.remove(oldScopedLabel);
}
}
use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.
the class TagUtils method getTagValue.
private static String getTagValue(DataObject dataObject, String tagName) {
if (dataObject == null || (dataObject.getTag() == null)) {
return null;
}
List<String> tags = new ArrayList<>();
for (ScopedLabel sl : dataObject.getTag()) {
tags.add("" + sl.getLabel());
}
Map<String, String> currentMachineTags = parseTags(tags);
return currentMachineTags.get(tagName);
}
use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.
the class VolumeBootVolumeMigration method tagBootVolumes.
/**
* For all volumes, fill in the boot volume tag, if certain loose criteria is met
*/
private void tagBootVolumes() {
log.info("Updating volumes to contain boot tag.");
DbClient dbClient = this.getDbClient();
List<URI> hostURIs = dbClient.queryByType(Host.class, false);
Iterator<Host> hosts = dbClient.queryIterativeObjects(Host.class, hostURIs);
while (hosts.hasNext()) {
Host host = hosts.next();
log.info("Examining Host (id={}) for boot volume upgrade", host.getId().toString());
// If there's no boot volume, there's nothing to upgrade.
if (NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
continue;
}
Volume volume = dbClient.queryObject(Volume.class, host.getBootVolumeId());
// if it's not in the DB, set it back to "null" on the host
if (volume == null) {
host.setBootVolumeId(NullColumnValueGetter.getNullURI());
dbClient.updateObject(host);
continue;
}
// If it's already a boot volume, move on
if (isVolumeBootVolume(volume)) {
continue;
}
// Add the tag.
ScopedLabelSet tagSet = volume.getTag();
if (tagSet == null) {
tagSet = new ScopedLabelSet();
volume.setTag(tagSet);
}
// Drop the new tag in the tag list
ScopedLabel tagLabel = new ScopedLabel(volume.getTenant().getURI().toString(), getBootVolumeTagName() + "=" + host.getId());
tagSet.add(tagLabel);
// Update the volume object
dbClient.updateObject(volume);
}
}
use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method setTag.
public void setTag(DataObject object, String scope, String label) {
if (label == null) {
// shouldn't happen
label = "";
}
ScopedLabel newScopedLabel = new ScopedLabel(scope, label);
ScopedLabelSet tagSet = object.getTag();
if (tagSet == null) {
tagSet = new ScopedLabelSet();
tagSet.add(newScopedLabel);
object.setTag(tagSet);
} else if (tagSet.contains(newScopedLabel)) {
return;
} else {
removeLabel(tagSet, scope);
tagSet.add(newScopedLabel);
}
_dbClient.persistObject(object);
}
Aggregations