Search in sources :

Example 6 with BadRequestException

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
    }
}
Also used : CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Test(org.junit.Test)

Example 7 with BadRequestException

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());
    }
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 8 with BadRequestException

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);
}
Also used : CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException)

Example 9 with BadRequestException

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);
}
Also used : CustomServicesDBResource(com.emc.storageos.db.client.model.uimodels.CustomServicesDBResource) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException)

Example 10 with BadRequestException

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);
}
Also used : KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) GeneralSecurityException(java.security.GeneralSecurityException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) KeyCertificateEntry(com.emc.storageos.security.keystore.impl.KeyCertificateEntry) Test(org.junit.Test)

Aggregations

BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)30 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)15 Operation (com.emc.storageos.db.client.model.Operation)14 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 URISyntaxException (java.net.URISyntaxException)13 FileShare (com.emc.storageos.db.client.model.FileShare)12 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)11 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 Path (javax.ws.rs.Path)11 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)10 Test (org.junit.Test)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)7 Consumes (javax.ws.rs.Consumes)7