use of com.emc.vipr.client.core.filters.ResourceFilter in project coprhd-controller by CoprHD.
the class BlockProvider method getAddMobilityGroupResources.
@Asset("addMobilityGroupResource")
@AssetDependencies("mobilityGroup")
public List<AssetOption> getAddMobilityGroupResources(AssetOptionsContext ctx, final URI mobilityGroupId) {
final ViPRCoreClient client = api(ctx);
VolumeGroupRestRep mobilityGroup = client.application().get(mobilityGroupId);
if (mobilityGroup.getMigrationGroupBy().equals(VolumeGroup.MigrationGroupBy.VOLUMES.name())) {
// VPLEX volumes that don't have reference to this mobility group
List<URI> volumeIds = client.blockVolumes().listBulkIds();
final ResourceFilter<VolumeRestRep> vplexFilter = new VplexVolumeFilter();
List<VolumeRestRep> volumes = client.blockVolumes().getByIds(volumeIds, new ResourceFilter<VolumeRestRep>() {
@Override
public boolean acceptId(URI id) {
return true;
}
@Override
public boolean accept(VolumeRestRep item) {
boolean accept = (item.getVolumeGroups() == null || !contains(item, mobilityGroupId)) && vplexFilter.accept(item);
if (accept) {
boolean rpProtection = (item.getProtection() != null && item.getProtection().getRpRep() != null && item.getProtection().getRpRep().getPersonality() != null);
if (rpProtection) {
// If RP+VPLEX protection specified, only allow RP SOURCE volumes to be listed
// as candidates for mobility groups. Exclude TARGETs and JOURNALs.
String personality = item.getProtection().getRpRep().getPersonality();
if (Volume.PersonalityTypes.TARGET.name().equals(personality) || Volume.PersonalityTypes.METADATA.name().equals(personality)) {
accept = false;
}
}
}
return accept;
}
private boolean contains(VolumeRestRep item, URI mobilityGroup) {
for (RelatedResourceRep vg : item.getVolumeGroups()) {
if (vg.getId().equals(mobilityGroup)) {
return true;
}
}
return false;
}
});
return createBaseResourceOptions(volumes);
} else if (mobilityGroup.getMigrationGroupBy().equals(VolumeGroup.MigrationGroupBy.HOSTS.name())) {
List<URI> hostIds = client.hosts().listBulkIds();
List<HostRestRep> hosts = client.hosts().getByIds(hostIds, new ResourceFilter<HostRestRep>() {
@Override
public boolean acceptId(URI id) {
return true;
}
@Override
public boolean accept(HostRestRep item) {
return item.getVolumeGroups() == null || !contains(item, mobilityGroupId);
}
private boolean contains(HostRestRep item, URI mobilityGroup) {
for (RelatedResourceRep vg : item.getVolumeGroups()) {
if (vg.getId().equals(mobilityGroup)) {
return true;
}
}
return false;
}
});
return createBaseResourceOptions(hosts);
} else if (mobilityGroup.getMigrationGroupBy().equals(VolumeGroup.MigrationGroupBy.CLUSTERS.name())) {
List<URI> clusterIds = client.clusters().listBulkIds();
List<ClusterRestRep> clusters = client.clusters().getByIds(clusterIds, new ResourceFilter<ClusterRestRep>() {
@Override
public boolean acceptId(URI id) {
return true;
}
@Override
public boolean accept(ClusterRestRep item) {
return item.getVolumeGroups() == null || !contains(item, mobilityGroupId);
}
private boolean contains(ClusterRestRep item, URI mobilityGroup) {
for (RelatedResourceRep vg : item.getVolumeGroups()) {
if (vg.getId().equals(mobilityGroup)) {
return true;
}
}
return false;
}
});
return createBaseResourceOptions(clusters);
} else {
return Lists.newArrayList();
}
}
Aggregations