Search in sources :

Example 1 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method switchoverPrecheck.

/**
 * This is internal API to do precheck for switchover
 *
 * @return return response with error message and service code
 */
@POST
@Path("/internal/switchoverprecheck")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SiteErrorResponse switchoverPrecheck() {
    log.info("Precheck for switchover internally");
    SiteErrorResponse response = new SiteErrorResponse();
    try {
        precheckForSwitchoverForLocalStandby();
    } catch (InternalServerErrorException e) {
        log.warn("Failed to precheck switchover", e);
        response.setErrorMessage(e.getMessage());
        response.setServiceCode(e.getServiceCode().ordinal());
        return response;
    } catch (Exception e) {
        log.error("Failed to precheck switchover", e);
        response.setErrorMessage(e.getMessage());
        return response;
    }
    return response;
}
Also used : SiteErrorResponse(com.emc.storageos.model.dr.SiteErrorResponse) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) RetryableCoordinatorException(com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException) UnknownHostException(java.net.UnknownHostException) Path(javax.ws.rs.Path) ZkPath(com.emc.storageos.coordinator.common.impl.ZkPath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 2 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException 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 3 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testPrecheckForPlannedFailover.

@Test
public void testPrecheckForPlannedFailover() {
    String standbyUUID = "a918ebd4-bbf4-378b-8034-b03423f9edfd";
    // test for invalid uuid
    try {
        APIException e = APIException.internalServerErrors.switchoverPrecheckFailed(standby.getUuid(), "Standby uuid is not valid, can't find in ZK");
        doThrow(e).when(drUtil).getSiteFromLocalVdc(standbyUUID);
        drService.precheckForSwitchover(standbyUUID);
        fail("should throw exception when met invalid standby uuid");
    } catch (InternalServerErrorException e) {
        assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
    }
    Site site = new Site();
    site.setUuid(standbyUUID);
    Configuration config = site.toConfiguration();
    // test for failover to primary
    try {
        // Mock a standby in coordinator, so it would pass invalid standby checking, go to next check
        doReturn(config).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbyUUID);
        drService.precheckForSwitchover(standbyUUID);
        fail("should throw exception when trying to failover to a primary site");
    } catch (InternalServerErrorException e) {
        assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
    }
    // test for primary unstable case
    try {
        // Mock a primary site with different uuid with to-be-failover standby, so go to next check
        doReturn(false).when(drService).isClusterStable();
        drService.precheckForSwitchover(standbyUUID);
        fail("should throw exception when primary is not stable");
    } catch (InternalServerErrorException e) {
        assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
    }
    // test for standby unstable case
    try {
        // Mock a stable status for primary, so go to next check
        doReturn(true).when(drService).isClusterStable();
        doReturn(ClusterInfo.ClusterState.DEGRADED).when(coordinator).getControlNodesState(eq(standbyUUID));
        drService.precheckForSwitchover(standbyUUID);
        fail("should throw exception when site to failover to is not stable");
    } catch (InternalServerErrorException e) {
        assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
    }
    // test for standby not STANDBY_CYNCED state
    try {
        // Mock a stable status for standby, so go to next check
        doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(anyString());
        // not fully synced
        config.setConfig("state", "STANDBY_SYNCING");
        doReturn(config).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbyUUID);
        drService.precheckForSwitchover(standbyUUID);
        fail("should throw exception when standby site is not fully synced");
    } catch (InternalServerErrorException e) {
        assertEquals(e.getServiceCode(), ServiceCode.SYS_DR_OPERATION_PRECHECK_FAILED);
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) Configuration(com.emc.storageos.coordinator.common.Configuration) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 4 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testUpdateSite.

@Test
public void testUpdateSite() {
    doReturn(standbySite1).when(drUtil).getSiteFromLocalVdc(standbySite1.getUuid());
    SiteUpdateParam updateParam = new SiteUpdateParam();
    try {
        drService.updateSite(standbySite1.getUuid(), updateParam);
        fail();
    } catch (InternalServerErrorException e) {
    // Ignore expected exception
    }
    updateParam.setName("New Name");
    updateParam.setDescription("New Description");
    drService.updateSite(standbySite1.getUuid(), updateParam);
}
Also used : InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) SiteUpdateParam(com.emc.storageos.model.dr.SiteUpdateParam) Test(org.junit.Test)

Example 5 with InternalServerErrorException

use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.

the class DbEventRetrieverTest method meteringServiceNullDBclientTestXML.

@Test
public void meteringServiceNullDBclientTestXML() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = null;
    MonitoringService eventResource = new MonitoringService();
    // statResource.setDbClient(dbClient);
    DbEventRetriever dummyDbStatRetriever = new DbEventRetriever();
    dummyDbStatRetriever.setDbClient(dbClient);
    eventResource.setEventRetriever(dummyDbStatRetriever);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    Response r = eventResource.getEvents("2012-01-02T00:00", header);
    Assert.assertNotNull(r);
    Assert.assertEquals(Status.OK.getStatusCode(), r.getStatus());
    Assert.assertTrue(r.getEntity() instanceof StreamingOutput);
    StreamingOutput so = (StreamingOutput) r.getEntity();
    File of = new File(XmlTestOutputFile);
    OutputStream os = new FileOutputStream(of);
    try {
        so.write(os);
    } catch (InternalServerErrorException e) {
        Assert.assertTrue(e.toString().contains("DB"));
    } finally {
        os.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) DbEventRetriever(com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever) MonitoringService(com.emc.storageos.api.service.impl.resource.MonitoringService) File(java.io.File) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Aggregations

InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)15 Test (org.junit.Test)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)6 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)5 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)5 UnknownHostException (java.net.UnknownHostException)5 POST (javax.ws.rs.POST)5 Produces (javax.ws.rs.Produces)5 Site (com.emc.storageos.coordinator.client.model.Site)4 ZkPath (com.emc.storageos.coordinator.common.impl.ZkPath)4 Path (javax.ws.rs.Path)4 DummyDBClient (com.emc.storageos.api.service.utils.DummyDBClient)3 DummyHttpHeaders (com.emc.storageos.api.service.utils.DummyHttpHeaders)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Response (javax.ws.rs.core.Response)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)3 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)3 MonitoringService (com.emc.storageos.api.service.impl.resource.MonitoringService)2 DbEventRetriever (com.emc.storageos.api.service.impl.resource.utils.DbEventRetriever)2 SiteConfigParam (com.emc.storageos.model.dr.SiteConfigParam)2