Search in sources :

Example 6 with InternalServerErrorException

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();
}
Also used : Response(javax.ws.rs.core.Response) DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) DbAuditLogRetriever(com.emc.storageos.api.service.impl.resource.utils.DbAuditLogRetriever) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuditService(com.emc.storageos.api.service.impl.resource.AuditService) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 7 with InternalServerErrorException

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());
    }
}
Also used : InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BackupException(com.emc.storageos.management.backup.exceptions.BackupException) ParseException(java.text.ParseException) Date(java.util.Date)

Example 8 with InternalServerErrorException

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());
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) CustomServicesConstants(com.emc.storageos.primitives.CustomServicesConstants) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) URI(java.net.URI) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)

Example 9 with InternalServerErrorException

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;
    }
}
Also used : InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) URI(java.net.URI) Test(org.junit.Test)

Example 10 with InternalServerErrorException

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