use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class RemoteRepositoryTest method testCatalogRepository.
@Test
public void testCatalogRepository() throws Exception {
repositoryUrl = CATALOG_SERVER_URL;
_repo = RemoteRepository.getInstance();
Assert.assertTrue(_repo != null);
final List<SoftwareVersion> remoteVersions = _repo.getVersions();
Assert.assertTrue(remoteVersions != null);
Assert.assertTrue(!remoteVersions.isEmpty());
for (SoftwareVersion v : remoteVersions) {
System.out.println(v);
}
int downloadableVersions = 0;
for (SoftwareVersion v : remoteVersions) {
try {
_repo.checkVersionDownloadable(v);
} catch (RemoteRepositoryException e) {
continue;
} catch (BadRequestException e) {
continue;
}
final InputStream in = _repo.getImageInputStream(v);
Assert.assertTrue(in != null);
byte[] buffer = new byte[0x10000];
Assert.assertTrue("getImageInputStream failed for " + v, in.read(buffer) > 0);
in.close();
downloadableVersions++;
}
// Make sure there are at least some downloadable versiosn
Assert.assertTrue(downloadableVersions > 0);
System.out.println("Found " + downloadableVersions + " downloadable versions out of " + remoteVersions.size());
SoftwareVersion version = null;
// avoid version 121 since it is bad
for (SoftwareVersion remoteVersion : remoteVersions) {
// / Avoid a specific version on the downloads test site because it is no good
if (0 != remoteVersion.compareTo(new SoftwareVersion("vipr-1.0.0.7.121"))) {
version = remoteVersion;
break;
}
}
Assert.assertNotNull(version);
File file = startBackgroundDownload(version);
Assert.assertNotNull(file);
while (_downloader.isDownloading()) {
System.out.println("Downloading " + file);
Thread.sleep(2000);
}
Assert.assertTrue(file.exists());
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class OrderServiceJobConsumer method consumeItem.
/**
* @param job The object provisioning job which is being worked on. This could be either creation or deletion job
* @param callback This must be executed, after the item is processed successfully to remove the item
* from the distributed queue
*
* @throws Exception
*/
@Override
public void consumeItem(OrderServiceJob job, DistributedQueueItemProcessedCallback callback) throws Exception {
while (true) {
try {
OrderJobStatus jobStatus = orderService.queryJobInfo(OrderServiceJob.JobType.DELETE_ORDER);
long startTime = jobStatus.getStartTime();
long endTime = jobStatus.getEndTime();
OrderStatus status = jobStatus.getStatus();
List<URI> tids = jobStatus.getTids();
List<URI> orderIds = new ArrayList();
log.info("jobstatus={}", jobStatus);
long total = 0;
long numberOfOrdersDeletedInGC = orderService.getDeletedOrdersInCurrentPeriodWithSort(jobStatus);
long numberOfOrdersCanBeDeletedInGC = maxOrderDeletedPerGC - numberOfOrdersDeletedInGC;
if (numberOfOrdersCanBeDeletedInGC <= 0) {
log.info("Max number of order objects ({}) have been deleted in the current GC period", maxOrderDeletedPerGC);
Thread.sleep(CHECK_INTERVAL);
continue;
}
boolean stop = false;
for (URI tid : tids) {
TimeSeriesConstraint constraint = TimeSeriesConstraint.Factory.getOrders(tid, startTime, endTime);
NamedElementQueryResultList ids = new NamedElementQueryResultList();
dbClient.queryByConstraint(constraint, ids);
for (NamedElementQueryResultList.NamedElement namedID : ids) {
URI id = namedID.getId();
Order order = orderManager.getOrderById(id);
try {
orderManager.canBeDeleted(order, status);
if (orderIds.size() < numberOfOrdersCanBeDeletedInGC) {
orderIds.add(id);
} else if (jobStatus.getTotal() != -1) {
stop = true;
break;
}
total++;
} catch (Exception e) {
continue;
}
}
if (stop) {
break;
}
}
if (jobStatus.getTotal() == -1) {
// It's the first time to run the job, so get the total number of orders to be deleted
jobStatus.setTotal(total);
orderService.saveJobInfo(jobStatus);
if (total == 0) {
log.info("No orders can be deleted");
break;
}
}
log.info("{} orders to be deleted within current GC period", orderIds.size());
long nDeleted = 0;
long nFailed = 0;
long start = System.currentTimeMillis();
long tempCount = 0;
for (URI id : orderIds) {
Order order = orderManager.getOrderById(id);
try {
log.info("To delete order {}", order.getId());
orderManager.deleteOrder(order);
nDeleted++;
tempCount++;
if (tempCount >= NUMBER_PER_RECORD) {
jobStatus.addCompleted(tempCount);
orderService.saveJobInfo(jobStatus);
tempCount = 0;
}
} catch (BadRequestException e) {
log.warn("Failed to delete order {} e=", id, e);
nFailed++;
jobStatus.setFailed(nFailed);
orderService.saveJobInfo(jobStatus);
} catch (Exception e) {
log.warn("Failed to delete order={} e=", id, e);
nFailed++;
jobStatus.setFailed(nFailed);
orderService.saveJobInfo(jobStatus);
}
}
if (tempCount > 0) {
jobStatus.addCompleted(tempCount);
orderService.saveJobInfo(jobStatus);
tempCount = 0;
}
long end = System.currentTimeMillis();
long speed = (end - start) / (nDeleted + nFailed);
jobStatus.setTimeUsedPerOrder(speed);
orderService.saveJobInfo(jobStatus);
if (jobStatus.isFinished()) {
break;
}
Thread.sleep(CHECK_INTERVAL);
} catch (Exception e) {
log.error("e=", e);
throw e;
}
}
log.info("remove order job from the queue");
callback.itemProcessed();
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class CustomServicesDBHelper method checkResourceNotReferenced.
private static <T extends CustomServicesDBResource> BadRequestException checkResourceNotReferenced(final Class<? extends ModelObject> referencedByClazz, final String referencedByColumnName, final ModelClient client, final URI resourceId, final T resource) {
List<NamedElement> resourceExistList = Collections.emptyList();
final BadRequestException resourceReferencedexception = null;
if (null != referencedByClazz) {
resourceExistList = client.findBy(referencedByClazz, referencedByColumnName, resourceId);
if (null != resourceExistList && !resourceExistList.isEmpty()) {
return APIException.badRequests.resourceHasActiveReferencesWithType(resource.getClass().getSimpleName(), resourceId, StringUtils.substringAfterLast(referencedByClazz.getName(), "."));
}
}
return resourceReferencedexception;
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class PlacementTests method testNegativeBasicRPPlacement.
/**
* Simple block placement with RP
* Basic RP Placement test - VMAX
* This is a negative test. Placement should fail.
*/
@Test
public void testNegativeBasicRPPlacement() {
String[] vmax1FE = { "50:FE:FE:FE:FE:FE:FE:00", "50:FE:FE:FE:FE:FE:FE:01" };
String[] vmax2FE = { "51:FE:FE:FE:FE:FE:FE:00", "51:FE:FE:FE:FE:FE:FE:01" };
String[] rp1FE = { "52:FE:FE:FE:FE:FE:FE:00", "52:FE:FE:FE:FE:FE:FE:01" };
String[] rp2FE = { "53:FE:FE:FE:FE:FE:FE:00", "53:FE:FE:FE:FE:FE:FE:01" };
// Create 2 Virtual Arrays
VirtualArray varray1 = PlacementTestUtils.createVirtualArray(_dbClient, "varray1");
VirtualArray varray2 = PlacementTestUtils.createVirtualArray(_dbClient, "varray2");
// Create 2 Networks
StringSet connVA = new StringSet();
connVA.add(varray1.getId().toString());
Network network1 = PlacementTestUtils.createNetwork(_dbClient, rp1FE, "VSANSite1", "FC+BROCADE+FE", connVA);
connVA = new StringSet();
connVA.add(varray2.getId().toString());
Network network2 = PlacementTestUtils.createNetwork(_dbClient, rp2FE, "VSANSite2", "FC+CISCO+FE", connVA);
// Create 2 storage systems
StorageSystem storageSystem1 = PlacementTestUtils.createStorageSystem(_dbClient, "vmax", "vmax1");
StorageSystem storageSystem2 = PlacementTestUtils.createStorageSystem(_dbClient, "vmax", "vmax2");
// Create two front-end storage ports VMAX1
List<StoragePort> vmax1Ports = new ArrayList<StoragePort>();
for (int i = 0; i < vmax1FE.length; i++) {
vmax1Ports.add(PlacementTestUtils.createStoragePort(_dbClient, storageSystem1, network1, vmax1FE[i], varray1, StoragePort.PortType.frontend.name(), "portGroupSite1vmax" + i, "C0+FC0" + i));
}
// Create two front-end storage ports VMAX2
List<StoragePort> vmax2Ports = new ArrayList<StoragePort>();
for (int i = 0; i < vmax2FE.length; i++) {
vmax2Ports.add(PlacementTestUtils.createStoragePort(_dbClient, storageSystem2, network2, vmax2FE[i], varray2, StoragePort.PortType.frontend.name(), "portGroupSite2vmax" + i, "D0+FC0" + i));
}
// Create RP system
AbstractChangeTrackingSet<String> wwnSite1 = new StringSet();
for (int i = 0; i < rp1FE.length; i++) {
wwnSite1.add(rp1FE[i]);
}
StringSetMap initiatorsSiteMap = new StringSetMap();
initiatorsSiteMap.put("site1", wwnSite1);
AbstractChangeTrackingSet<String> wwnSite2 = new StringSet();
for (int i = 0; i < rp2FE.length; i++) {
wwnSite2.add(rp2FE[i]);
}
initiatorsSiteMap.put("site2", wwnSite2);
StringSet storSystems = new StringSet();
storSystems.add(ProtectionSystem.generateAssociatedStorageSystem("site1", storageSystem1.getSerialNumber()));
storSystems.add(ProtectionSystem.generateAssociatedStorageSystem("site2", storageSystem2.getSerialNumber()));
StringMap siteVolCap = new StringMap();
siteVolCap.put("site1", "3221225472");
siteVolCap.put("site2", "3221225472");
StringMap siteVolCnt = new StringMap();
siteVolCnt.put("site1", "10");
siteVolCnt.put("site2", "10");
ProtectionSystem rpSystem = PlacementTestUtils.createProtectionSystem(_dbClient, "rp", "rp1", "site1", "site2", null, "IP", initiatorsSiteMap, storSystems, null, Long.valueOf("3221225472"), Long.valueOf("2"), siteVolCap, siteVolCnt);
// RP Site Array objects
RPSiteArray rpSiteArray1 = new RPSiteArray();
rpSiteArray1.setId(URI.create("rsa1"));
rpSiteArray1.setStorageSystem(URI.create("vmax1"));
rpSiteArray1.setRpInternalSiteName("site1");
rpSiteArray1.setRpProtectionSystem(rpSystem.getId());
_dbClient.createObject(rpSiteArray1);
RPSiteArray rpSiteArray2 = new RPSiteArray();
rpSiteArray2.setId(URI.create("rsa2"));
rpSiteArray2.setStorageSystem(URI.create("vmax2"));
rpSiteArray2.setRpInternalSiteName("site2");
rpSiteArray2.setRpProtectionSystem(rpSystem.getId());
_dbClient.createObject(rpSiteArray2);
// Create a storage pool for vmax1
StoragePool pool1 = PlacementTestUtils.createStoragePool(_dbClient, varray1, storageSystem1, "pool1", "Pool1", Long.valueOf(SIZE_GB * 1), Long.valueOf(SIZE_GB * 10), 300, 300, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a storage pool for vmax1
StoragePool pool2 = PlacementTestUtils.createStoragePool(_dbClient, varray1, storageSystem1, "pool2", "Pool2", Long.valueOf(SIZE_GB * 1), Long.valueOf(SIZE_GB * 10), 300, 300, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a storage pool for vmax1
StoragePool pool3 = PlacementTestUtils.createStoragePool(_dbClient, varray1, storageSystem1, "pool3", "Pool3", Long.valueOf(SIZE_GB * 1), Long.valueOf(SIZE_GB * 1), 100, 100, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a storage pool for vmax2
StoragePool pool4 = PlacementTestUtils.createStoragePool(_dbClient, varray2, storageSystem2, "pool4", "Pool4", Long.valueOf(SIZE_GB * 10), Long.valueOf(SIZE_GB * 10), 300, 300, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a storage pool for vmax2
StoragePool pool5 = PlacementTestUtils.createStoragePool(_dbClient, varray2, storageSystem2, "pool5", "Pool5", Long.valueOf(SIZE_GB * 10), Long.valueOf(SIZE_GB * 10), 300, 300, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a storage pool for vmax2
StoragePool pool6 = PlacementTestUtils.createStoragePool(_dbClient, varray2, storageSystem2, "pool6", "Pool6", Long.valueOf(SIZE_GB * 1), Long.valueOf(SIZE_GB * 1), 100, 100, StoragePool.SupportedResourceTypes.THIN_ONLY.toString());
// Create a RP virtual pool
VirtualPool rpTgtVpool = new VirtualPool();
rpTgtVpool.setId(URI.create("rpTgtVpool"));
rpTgtVpool.setLabel("rpTgtVpool");
rpTgtVpool.setSupportedProvisioningType(VirtualPool.ProvisioningType.Thin.name());
rpTgtVpool.setDriveType(SupportedDriveTypes.FC.name());
VpoolProtectionVarraySettings protectionSettings = new VpoolProtectionVarraySettings();
protectionSettings.setVirtualPool(URI.create("vpool"));
protectionSettings.setId(URI.create("protectionSettings"));
_dbClient.createObject(protectionSettings);
List<VpoolProtectionVarraySettings> protectionSettingsList = new ArrayList<VpoolProtectionVarraySettings>();
protectionSettingsList.add(protectionSettings);
StringMap protectionVarray = new StringMap();
protectionVarray.put(varray2.getId().toString(), protectionSettingsList.get(0).getId().toString());
rpTgtVpool.setProtectionVarraySettings(protectionVarray);
rpTgtVpool.setRpCopyMode("SYNCHRONOUS");
rpTgtVpool.setRpRpoType("MINUTES");
rpTgtVpool.setRpRpoValue(Long.valueOf("5"));
StringSet matchedPools = new StringSet();
matchedPools.add(pool1.getId().toString());
matchedPools.add(pool2.getId().toString());
matchedPools.add(pool3.getId().toString());
rpTgtVpool.setMatchedStoragePools(matchedPools);
rpTgtVpool.setUseMatchedPools(true);
StringSet virtualArrays1 = new StringSet();
virtualArrays1.add(varray1.getId().toString());
rpTgtVpool.setVirtualArrays(virtualArrays1);
_dbClient.createObject(rpTgtVpool);
// Create a virtual pool
VirtualPool rpSrcVpool = new VirtualPool();
rpSrcVpool.setId(URI.create("vpool"));
rpSrcVpool.setLabel("vpool");
rpSrcVpool.setSupportedProvisioningType(VirtualPool.ProvisioningType.Thin.name());
rpSrcVpool.setDriveType(SupportedDriveTypes.FC.name());
matchedPools = new StringSet();
matchedPools.add(pool4.getId().toString());
matchedPools.add(pool5.getId().toString());
matchedPools.add(pool6.getId().toString());
rpSrcVpool.setMatchedStoragePools(matchedPools);
rpSrcVpool.setUseMatchedPools(true);
StringSet virtualArrays2 = new StringSet();
virtualArrays2.add(varray2.getId().toString());
rpSrcVpool.setVirtualArrays(virtualArrays2);
_dbClient.createObject(rpSrcVpool);
// Create Tenant
TenantOrg tenant = new TenantOrg();
tenant.setId(URI.create("tenant"));
_dbClient.createObject(tenant);
// Create a project object
Project project = new Project();
project.setId(URI.create("project"));
project.setLabel("project");
project.setTenantOrg(new NamedURI(tenant.getId(), project.getLabel()));
_dbClient.createObject(project);
// Create block consistency group
BlockConsistencyGroup cg = new BlockConsistencyGroup();
cg.setProject(new NamedURI(project.getId(), project.getLabel()));
cg.setId(URI.create("blockCG"));
_dbClient.createObject(cg);
// Create capabilities
VirtualPoolCapabilityValuesWrapper capabilities = PlacementTestUtils.createCapabilities("2GB", 1, cg);
// requested size of volume.
for (int i = 0; i < 10; i++) {
boolean caught = false;
List recommendations = null;
try {
recommendations = PlacementTestUtils.invokePlacement(_dbClient, _coordinator, varray1, project, rpTgtVpool, capabilities);
} catch (BadRequestException e) {
caught = true;
_log.info("Caught expected Exception", e);
}
assertTrue(caught);
}
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class CustomAuthenticationManagerTest method testGetUserGroups.
@Test
public void testGetUserGroups() throws Exception {
cleanupProviders();
AuthnProvider authConfig = createValidAuthProviderInDB();
final String DOMAIN_USERS_GROUP = "Domain Users@sanity.local";
final String OUTER_GROUP = "OuterGroup@sanity.local";
final String INNER_GROUP = "InsideGroup@sanity.local";
// look for a user with an unsupported domain
String principalSearchFailedFormat = "Search for %s failed for this tenant, or could not be found for this tenant.";
String user = "invaliduser@invalidDomain.com";
UserDetails userDetails = null;
try {
userDetails = _authManager.getUserDetails(user);
Assert.assertNull(userDetails);
} catch (SecurityException e) {
Assert.fail("Got a SecurityException when BadRequestException was expected. Details: " + e.getLocalizedMessage());
} catch (BadRequestException e) {
assertServiceError(HttpStatus.SC_BAD_REQUEST, ServiceCode.API_BAD_REQUEST, String.format(principalSearchFailedFormat, user), e);
} catch (Exception e) {
Assert.fail("Got a " + e.getClass().toString() + "when BadRequestException was expected. Details: " + e.getLocalizedMessage());
}
// look for a user that doesn't exist
user = "iShouldntExistAnywhereInTheWholeWideWorld@sanity.local";
try {
_authManager.getUserDetails(user);
Assert.assertNull(userDetails);
} catch (SecurityException e) {
Assert.fail("Got a SecurityException when BadRequestException was expected. Details: " + e.getLocalizedMessage());
} catch (BadRequestException e) {
assertServiceError(HttpStatus.SC_BAD_REQUEST, ServiceCode.API_BAD_REQUEST, String.format(principalSearchFailedFormat, user), e);
} catch (Exception e) {
Assert.fail("Got a " + e.getClass().toString() + "when BadRequestException was expected. Details: " + e.getLocalizedMessage());
}
// look for a user that does exist
user = "userGroupsTestUser@sanity.local";
try {
userDetails = _authManager.getUserDetails(user);
Assert.assertNotNull(userDetails);
Assert.assertEquals(3, userDetails.getUserGroupList().size());
Assert.assertTrue("user is supposed to be part of the root tenant " + _rootTenantId + "but is actually in tenant" + userDetails.getTenant(), _rootTenantId.toString().equals(userDetails.getTenant()));
boolean isDomainUser = false;
boolean isInsideGroup = false;
boolean isOuterGroup = false;
for (String groupName : userDetails.getUserGroupList()) {
if (groupName.equalsIgnoreCase(DOMAIN_USERS_GROUP)) {
isDomainUser = true;
} else if (groupName.equalsIgnoreCase(INNER_GROUP)) {
isInsideGroup = true;
} else if (groupName.equalsIgnoreCase(OUTER_GROUP)) {
isOuterGroup = true;
}
}
Assert.assertTrue("isDomainUser = " + isDomainUser + ", isInsideGroup = " + isInsideGroup + ", isOuterGroup = " + isOuterGroup, isDomainUser && isInsideGroup && isOuterGroup);
} catch (SecurityException e) {
Assert.fail("Got a SecurityException. Details: " + e.getLocalizedMessage());
} catch (BadRequestException e) {
Assert.fail("Got a BadRequestException. Details: " + e.getLocalizedMessage());
} catch (Exception e) {
Assert.fail("Got a " + e.getClass().toString() + ". Details: " + e.getLocalizedMessage());
}
// now test the returned user has the right tenant- it should now be mapped to the
// subtenant
UserMapping tenantMapping = new UserMapping();
tenantMapping.setDomain("sanity.local");
tenantMapping.setGroups(Collections.singletonList(OUTER_GROUP.split("@")[0]));
StringSetMap mappings = new StringSetMap();
mappings.put(tenantMapping.getDomain(), tenantMapping.toString());
URI subtenantId = URIUtil.createId(TenantOrg.class);
TenantOrg subtenant = new TenantOrg();
subtenant.setLabel("subtenant for user groups test");
subtenant.setDescription("auth subtenan1t");
subtenant.setId(subtenantId);
subtenant.setParentTenant(new NamedURI(_rootTenantId, "subtenant"));
subtenant.setUserMappings(mappings);
_dbClient.persistObject(subtenant);
try {
userDetails = _authManager.getUserDetails(user);
Assert.assertNotNull(userDetails);
Assert.assertEquals(3, userDetails.getUserGroupList().size());
boolean isDomainUser = false;
boolean isInsideGroup = false;
boolean isOuterGroup = false;
for (String groupName : userDetails.getUserGroupList()) {
if (groupName.equalsIgnoreCase(DOMAIN_USERS_GROUP)) {
isDomainUser = true;
} else if (groupName.equalsIgnoreCase(INNER_GROUP)) {
isInsideGroup = true;
} else if (groupName.equalsIgnoreCase(OUTER_GROUP)) {
isOuterGroup = true;
}
}
Assert.assertTrue("isDomainUser = " + isDomainUser + ", isInsideGroup = " + isInsideGroup + ", isOuterGroup = " + isOuterGroup, isDomainUser && isInsideGroup && isOuterGroup);
Assert.assertTrue("user is supposed to be part of the subtenant " + subtenantId + " but is actually in tenant " + userDetails.getTenant() + " (root tenant is " + _rootTenantId + " )", subtenantId.toString().equals(userDetails.getTenant()));
} catch (SecurityException e) {
Assert.fail("Got a SecurityException. Details: " + e.getLocalizedMessage());
} catch (BadRequestException e) {
Assert.fail("Got a BadRequestException. Details: " + e.getLocalizedMessage());
} catch (Exception e) {
Assert.fail("Got a " + e.getClass().toString() + ". Details: " + e.getLocalizedMessage());
}
}
Aggregations