Search in sources :

Example 1 with SchemaValidationFailedException

use of com.hortonworks.streamline.common.exception.SchemaValidationFailedException in project streamline by hortonworks.

the class TopologyTestRunResource method validateTestRunCaseSource.

@POST
@Path("/topologies/{topologyId}/testcases/{testCaseId}/sources/{id}/validate")
@Timed
public Response validateTestRunCaseSource(@PathParam("topologyId") Long topologyId, @PathParam("testCaseId") Long testCaseId, @PathParam("id") Long id, @Context SecurityContext securityContext) throws IOException {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
    TopologyTestRunCaseSource testCaseSource = catalogService.getTopologyTestRunCaseSource(testCaseId, id);
    if (testCaseSource == null) {
        throw EntityNotFoundException.byId(Long.toString(id));
    }
    try {
        doValidationForTestRunCaseSource(topologyId, testCaseId, testCaseSource);
        return WSUtils.respondEntity(Collections.singletonMap("status", "valid"), OK);
    } catch (SchemaValidationFailedException e) {
        throw handleSchemaValidationFailedException(topologyId, testCaseSource, e);
    }
}
Also used : TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) SchemaValidationFailedException(com.hortonworks.streamline.common.exception.SchemaValidationFailedException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with SchemaValidationFailedException

use of com.hortonworks.streamline.common.exception.SchemaValidationFailedException in project streamline by hortonworks.

the class TopologyTestRunResource method testRunTopology.

@POST
@Path("/topologies/{topologyId}/actions/testrun")
@Timed
public Response testRunTopology(@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, TopologyTestRunParam topologyTestRunParam, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, EXECUTE);
    Topology result = catalogService.getTopology(topologyId);
    if (result != null) {
        Long testCaseId = topologyTestRunParam.getTestCaseId();
        Long durationSecs = topologyTestRunParam.getDurationSecs();
        if (testCaseId == null) {
            throw BadRequestException.missingParameter("testCaseId");
        }
        TopologyTestRunCase testCase = catalogService.getTopologyTestRunCase(topologyId, testCaseId);
        if (testCase == null) {
            throw EntityNotFoundException.byName("topology " + topologyId + " / topology test case " + testCaseId);
        }
        Collection<TopologyTestRunCaseSource> testCaseSources = catalogService.listTopologyTestRunCaseSource(testCaseId);
        if (testCaseSources != null) {
            for (TopologyTestRunCaseSource source : testCaseSources) {
                try {
                    doValidationForTestRunCaseSource(topologyId, testCaseId, source);
                } catch (SchemaValidationFailedException e) {
                    throw handleSchemaValidationFailedException(topologyId, source, e);
                }
            }
        }
        TopologyTestRunHistory history = actionsService.testRunTopology(result, testCase, durationSecs);
        return WSUtils.respondEntity(history, OK);
    }
    throw EntityNotFoundException.byName("topology " + topologyId.toString());
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) SchemaValidationFailedException(com.hortonworks.streamline.common.exception.SchemaValidationFailedException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)2 SchemaValidationFailedException (com.hortonworks.streamline.common.exception.SchemaValidationFailedException)2 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 Topology (com.hortonworks.streamline.streams.catalog.Topology)1 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)1 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)1