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;
}
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
}
}
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);
}
}
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);
}
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();
}
}
Aggregations