use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class DisasterRecoveryServiceTest method testPrecheckForFailover_Error.
@Test
public void testPrecheckForFailover_Error() {
// API should be only send to local site
try {
doReturn(standbySite2).when(drUtil).getLocalSite();
drService.precheckForFailover();
fail();
} catch (InternalServerErrorException e) {
// ignore
}
// should be synced
try {
doReturn(standbySite1).when(drUtil).getLocalSite();
standbySite1.setState(SiteState.STANDBY_ERROR);
drService.precheckForFailover();
fail();
} catch (InternalServerErrorException e) {
// ignore
}
// show be only standby
try {
standbySite1.setState(SiteState.STANDBY_SYNCED);
doReturn(true).when(drUtil).isActiveSite();
drService.precheckForFailover();
fail();
} catch (InternalServerErrorException | BadRequestException e) {
// ignore
}
// should be stable
try {
doReturn(false).when(drUtil).isActiveSite();
doReturn(ClusterInfo.ClusterState.DEGRADED).when(coordinator).getControlNodesState(standbySite1.getUuid());
drService.precheckForFailover();
fail();
} catch (InternalServerErrorException e) {
// ignore
}
// ZK should not be observer or read-only
try {
CoordinatorClientInetAddressMap addrLookupMap = new CoordinatorClientInetAddressMap();
addrLookupMap.setNodeId("vipr1");
doReturn(addrLookupMap).when(coordinator).getInetAddessLookupMap();
doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(standbySite1.getUuid());
doReturn("observer").when(drUtil).getLocalCoordinatorMode();
drService.precheckForFailover();
fail();
} catch (InternalServerErrorException e) {
// ignore
}
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class DbStatRetrieverTest method xmlStatIllegalTimeBucketArgumentTest.
@Test
public void xmlStatIllegalTimeBucketArgumentTest() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
MeteringService statResource = new MeteringService();
statResource.setDbClient(dbClient);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
try {
statResource.getStats("xxxyyy", header);
Assert.fail("Expected a BadRequestException");
} catch (BadRequestException e) {
Assert.assertEquals(ServiceCode.API_PARAMETER_INVALID_TIME_FORMAT, e.getServiceCode());
}
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class CustomServicesDBHelper method deactivateResource.
/**
* Deactivate a resource database instance
*
* @param dbModel The database column family class
* @param primitiveManager The database access component
* @param client The model client
* @param id ID of the resource to deactivate
*/
public static void deactivateResource(final Class<? extends CustomServicesDBResource> dbModel, final CustomServicesPrimitiveManager primitiveManager, final ModelClient client, final URI id, final Class<? extends CustomServicesDBResource> referencedByResource, final String referencedByResourceColumnName, final Class<? extends CustomServicesDBPrimitive> referencedByPrimitive, final String referencedByPrimitiveColumnName) {
final CustomServicesDBResource resource = primitiveManager.findResource(dbModel, id);
if (null == resource) {
throw APIException.notFound.unableToFindEntityInURL(id);
}
BadRequestException resourceReferencedexception = checkResourceNotReferenced(referencedByPrimitive, referencedByPrimitiveColumnName, client, id, resource);
if (resourceReferencedexception != null) {
throw resourceReferencedexception;
}
resourceReferencedexception = checkResourceNotReferenced(referencedByResource, referencedByResourceColumnName, client, id, resource);
if (resourceReferencedexception != null) {
throw resourceReferencedexception;
}
client.delete(resource);
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class CustomServicesDBHelper method updateResource.
/**
* Given a resource ID and parameters update a resource in the database
*
* @param dbModel The database column family of the resource
* @param primitiveManager The database access component
* @param id The ID of the resource
* @param name The new name of the resource null, if no update
* @param stream The new bytes of the resource, null if no update
* @param attributes The new attributes of the resource, null if no update
* @return The updated java object instance of this resource type
*/
public static <T extends CustomServicesDBResourceType<?>> T updateResource(final Class<T> type, final Class<? extends CustomServicesDBResource> dbModel, final CustomServicesPrimitiveManager primitiveManager, final URI id, final String name, final byte[] stream, final StringSetMap attributes, final URI parentId, final ModelClient client, final Class<? extends CustomServicesDBResource> referencedByResource, final String referencedByResourceColumnName, final Class<? extends CustomServicesDBPrimitive> referencedByPrimitive, final String referencedByPrimitiveColumnName) {
final CustomServicesDBResource resource = primitiveManager.findResource(dbModel, id);
if (null == resource) {
throw APIException.notFound.unableToFindEntityInURL(id);
} else if (resource.getInactive()) {
throw APIException.notFound.entityInURLIsInactive(id);
}
if (StringUtils.isNotBlank(name)) {
final String label = name.trim();
if (!label.equalsIgnoreCase(resource.getLabel())) {
checkDuplicateLabel(label, primitiveManager, dbModel);
resource.setLabel(label);
}
}
if (null != parentId) {
resource.setParentId(parentId);
}
if (null != attributes || null != stream) {
BadRequestException resourceReferencedexception = checkResourceNotReferenced(referencedByPrimitive, referencedByPrimitiveColumnName, client, id, resource);
if (resourceReferencedexception != null) {
throw resourceReferencedexception;
}
resourceReferencedexception = checkResourceNotReferenced(referencedByResource, referencedByResourceColumnName, client, id, resource);
if (resourceReferencedexception != null) {
throw resourceReferencedexception;
}
resource.setAttributes(attributes);
resource.setResource(Base64.encodeBase64(stream));
}
primitiveManager.save(resource);
return makeResourceType(type, resource);
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class KeyCertificatePairGeneratorTest method testVerifyKeyCertificateEntry.
@Test
public void testVerifyKeyCertificateEntry() {
KeyCertificatePairGenerator gen = new KeyCertificatePairGenerator();
gen.setKeyCertificateAlgorithmValuesHolder(defaultValues);
// test a generated entry
KeyCertificateEntry entry1 = gen.generateKeyCertificatePair();
try {
new KeyCertificatePairGenerator().verifyKeyCertificateEntry(entry1);
} catch (SecurityException e) {
System.err.println(e.getMessage());
System.err.println(e);
Assert.fail();
} catch (BadRequestException e) {
System.err.println(e.getMessage());
System.err.println(e);
Assert.fail();
}
// test values from 2 different generated entries
KeyCertificateEntry entry2 = gen.generateKeyCertificatePair();
KeyCertificateEntry hybridEntry = new KeyCertificateEntry(entry1.getKey(), entry2.getCertificateChain());
boolean exceptionThrown = false;
try {
new KeyCertificatePairGenerator().verifyKeyCertificateEntry(hybridEntry);
} catch (SecurityException e) {
Assert.fail();
} catch (BadRequestException e) {
exceptionThrown = true;
}
Assert.assertTrue(exceptionThrown);
}
Aggregations