use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.
the class DbAuditLogRetrieverTest method auditServiceNullDBclientTestXML.
@Test
public void auditServiceNullDBclientTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = null;
AuditService auditResource = new AuditService();
DbAuditLogRetriever dummyDbAuditLogRetriever = new DbAuditLogRetriever();
dummyDbAuditLogRetriever.setDbClient(dbClient);
auditResource.setAuditLogRetriever(dummyDbAuditLogRetriever);
DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
Response r = auditResource.getAuditLogs("2012-01-05T00:00", "en_US", 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"));
}
os.close();
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.
the class BackupExecutor method doBackup.
private void doBackup() throws Exception {
String tag = null;
Exception lastException = null;
int retryCount = 0;
List<String> descParams = null;
while (shouldDoBackup()) {
try {
Date backupTime = this.cfg.now().getTime();
tag = ScheduledBackupTag.toBackupTag(backupTime, this.cfg.getSoftwareVersion(), this.cfg.nodeCount);
log.info("Starting backup using tag {} (retry #{})", tag, retryCount);
this.cli.createBackup(tag);
this.cfg.retainedBackups.add(tag);
this.cfg.persist();
return;
} catch (InternalServerErrorException e) {
lastException = e;
log.error(String.format("Exception when creating backup %s (retry #%d)", tag, retryCount), e);
}
if (retryCount == BackupConstants.BACKUP_RETRY_COUNT) {
break;
}
retryCount++;
Thread.sleep(BackupConstants.SCHEDULER_SLEEP_TIME_FOR_UPGRADING);
}
if (lastException != null) {
this.cfg.sendBackupFailureToRoot(tag, lastException.getMessage());
}
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.
the class CustomServicesViprExecution method makeRestCall.
private CustomServicesTaskResult makeRestCall(final URI uri, final Object requestBody, final String method) throws InternalServerErrorException {
ClientResponse response = null;
String responseString = null;
CustomServicesConstants.RestMethods restmethod = CustomServicesConstants.RestMethods.valueOf(method);
try {
switch(restmethod) {
case GET:
response = client.getURI(ClientResponse.class, uri);
break;
case PUT:
response = client.putURI(ClientResponse.class, requestBody, uri);
break;
case POST:
response = client.postURI(ClientResponse.class, requestBody, uri);
break;
case DELETE:
response = client.deleteURI(ClientResponse.class, uri);
break;
default:
throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Invalid REST method type" + method);
}
if (response == null) {
ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "REST Execution Failed. Response returned is null");
throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("REST Execution Failed. Response returned is null");
}
logger.info("Status of ViPR REST Operation:{} is :{}", primitive.name(), response.getStatus());
responseString = IOUtils.toString(response.getEntityInputStream(), "UTF-8");
final Map<URI, String> taskState = waitForTask(responseString);
// update state
final String classname = primitive.response();
if (classname.contains(RESTHelper.TASKLIST)) {
responseString = updateState(responseString, taskState);
}
return new CustomServicesTaskResult(responseString, responseString, response.getStatus(), taskState);
} catch (final InternalServerErrorException e) {
logger.warn("Exception received:{}", e);
if (e.getServiceCode().getCode() == ServiceCode.CUSTOM_SERVICE_NOTASK.getCode()) {
return new CustomServicesTaskResult(responseString, responseString, response.getStatus(), null);
}
ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), e);
throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Failed to Execute REST request" + e.getMessage());
} catch (final Exception e) {
logger.warn("Exception:", e);
ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), e);
throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("REST Execution Failed" + e.getMessage());
}
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.
the class KeystoneUtilsTest method testTagProjectWithOpenstackIdNullProject.
@Test(expected = InternalServerErrorException.class)
public void testTagProjectWithOpenstackIdNullProject() {
URI projectId = project.getId();
URI tenantId = tenantOrg.getId();
when(_dbClient.queryObject(Project.class, projectId)).thenReturn(null);
try {
_keystoneUtils.tagProjectWithOpenstackId(projectId, TENANT_OS_ID, tenantId.toString());
} catch (InternalServerErrorException apiException) {
assertEquals(ServiceCode.SYS_IS_NULL_OR_EMPTY, apiException.getServiceCode());
throw apiException;
}
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException in project coprhd-controller by CoprHD.
the class DbEventRetrieverTest method meteringServiceDBExceptionsTestXML.
@Test
public void meteringServiceDBExceptionsTestXML() throws WebApplicationException, IOException, JAXBException {
deleteIfExists(XmlTestOutputFile);
DummyDBClient dbClient = new DummyDBClient();
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("I/O"));
} finally {
os.close();
}
}
Aggregations