Search in sources :

Example 1 with TopologyBranchRule

use of com.hortonworks.streamline.streams.catalog.TopologyBranchRule in project streamline by hortonworks.

the class BranchRuleCatalogResource method getTopologyBranchRuleById.

/**
 * <p>
 * Gets a specific branch rule by Id. For example,
 * </p>
 * <b>GET /api/v1/catalog/topologies/:TOPOLOGY_ID/branchrules/:RULE_ID</b>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 1,
 *     "topologyId": 1,
 *     "name": "rule1",
 *     "description": "rule test",
 *     "actions": ...
 *   }
 * }
 * </pre>
 */
@GET
@Path("/topologies/{topologyId}/branchrules/{id}")
@Timed
public Response getTopologyBranchRuleById(@PathParam("topologyId") Long topologyId, @PathParam("id") Long ruleId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
    TopologyBranchRule brRuleInfo = catalogService.getBranchRule(topologyId, ruleId);
    if (brRuleInfo != null && brRuleInfo.getTopologyId().equals(topologyId)) {
        return WSUtils.respondEntity(brRuleInfo, OK);
    }
    throw EntityNotFoundException.byId(buildMessageForCompositeId(topologyId, ruleId));
}
Also used : TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with TopologyBranchRule

use of com.hortonworks.streamline.streams.catalog.TopologyBranchRule in project streamline by hortonworks.

the class BranchRuleCatalogResource method removeRule.

/**
 * <p>
 * Removes a branch rule.
 * </p>
 * <b>DELETE /api/v1/catalog/topologies/:TOPOLOGY_ID/branchrules/:RULE_ID</b>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 1,
 *     "topologyId": 1,
 *     "name": "rule1",
 *     "description": "rule test",
 *     "condition": "humidity > 90 AND celciusToFarenheit(temperature) > 80",
 *     "actions": ...
 *   }
 * }
 * </pre>
 */
@DELETE
@Path("/topologies/{topologyId}/branchrules/{id}")
@Timed
public Response removeRule(@PathParam("topologyId") Long topologyId, @PathParam("id") Long ruleId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, WRITE);
    TopologyBranchRule ruleInfo = catalogService.removeBranchRule(topologyId, ruleId);
    if (ruleInfo != null) {
        return WSUtils.respondEntity(ruleInfo, OK);
    }
    throw EntityNotFoundException.byId(buildMessageForCompositeId(topologyId, ruleId));
}
Also used : TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with TopologyBranchRule

use of com.hortonworks.streamline.streams.catalog.TopologyBranchRule in project streamline by hortonworks.

the class BranchRuleCatalogResource method addTopologyRule.

/**
 * <p>
 * Creates a topology branch rule. For example,
 * </p>
 * <b>POST /api/v1/catalog/topologies/:TOPOLOGY_ID/branchrules</b>
 * <pre>
 * {
 *   "name": "rule1",
 *   "description": "rule test",
 *   "condition": "humidity > 90 AND celciusToFarenheit(temperature) > 80",
 *   "actions": ...
 * }
 * </pre>
 * <i>Sample success response: </i>
 * <pre>
 * {
 *   "responseCode": 1000,
 *   "responseMessage": "Success",
 *   "entity": {
 *     "id": 1,
 *     "topologyId": 1,
 *     "name": "rule1",
 *     "description": "rule test",
 *     "condition": "humidity > 90 AND celciusToFarenheit(temperature) > 80",
 *     "actions": ...
 *   }
 * }
 * </pre>
 *
 * <i>
 * Note:
 * </i>
 *  <ol>
 *      <li>'celciusToFarenheit' is a user defined function defined via UDFCatalogResource (/api/v1/catalog/udfs) api.</li>
 *      <li>'temperature' and 'humidity' are the fields of the 'nest' output stream which should have been defined via
 *      the TopologyStreamCatalogResource (/api/v1/catalog/topologies/{topologyId}/streams) api.</li>
 */
@POST
@Path("/topologies/{topologyId}/branchrules")
@Timed
public Response addTopologyRule(@PathParam("topologyId") Long topologyId, TopologyBranchRule brRuleInfo, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, WRITE);
    TopologyBranchRule createdTopologyBranchRule = catalogService.addBranchRule(topologyId, brRuleInfo);
    return WSUtils.respondEntity(createdTopologyBranchRule, CREATED);
}
Also used : TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with TopologyBranchRule

use of com.hortonworks.streamline.streams.catalog.TopologyBranchRule in project streamline by hortonworks.

the class StreamCatalogService method copyTopologyDependencies.

private void copyTopologyDependencies(Long topologyId, Long oldVersionId, Long newVersionId) throws Exception {
    List<QueryParam> topologyIdVersionIdQueryParams = WSUtils.buildTopologyIdAndVersionIdAwareQueryParams(topologyId, oldVersionId, null);
    // topology editor metadata
    TopologyEditorMetadata metadata = getTopologyEditorMetadata(topologyId, oldVersionId);
    if (metadata != null) {
        addTopologyEditorMetadata(topologyId, newVersionId, new TopologyEditorMetadata(metadata));
    }
    // sources, output streams
    Collection<TopologySource> sources = listTopologySources(topologyIdVersionIdQueryParams);
    for (TopologySource source : sources) {
        addTopologySource(topologyId, newVersionId, new TopologySource(source));
    }
    // processors, output streams
    Collection<TopologyProcessor> processors = listTopologyProcessors(topologyIdVersionIdQueryParams);
    for (TopologyProcessor processor : processors) {
        addTopologyProcessor(topologyId, newVersionId, new TopologyProcessor(processor));
    }
    // add sinks
    Collection<TopologySink> sinks = listTopologySinks(topologyIdVersionIdQueryParams);
    for (TopologySink sink : sinks) {
        addTopologySink(topologyId, newVersionId, new TopologySink(sink));
    }
    // branch rules
    Collection<TopologyBranchRule> topologyBranchRules = listBranchRules(topologyIdVersionIdQueryParams);
    for (TopologyBranchRule topologyBranchRule : topologyBranchRules) {
        addBranchRule(topologyId, newVersionId, new TopologyBranchRule(topologyBranchRule));
    }
    // windowed rules
    Collection<TopologyWindow> topologyWindows = listWindows(topologyIdVersionIdQueryParams);
    for (TopologyWindow topologyWindow : topologyWindows) {
        addWindow(topologyId, newVersionId, new TopologyWindow(topologyWindow));
    }
    // rules
    Collection<TopologyRule> topologyRules = listRules(topologyIdVersionIdQueryParams);
    for (TopologyRule topologyRule : topologyRules) {
        addRule(topologyId, newVersionId, new TopologyRule(topologyRule));
    }
    // add edges
    Collection<TopologyEdge> edges = listTopologyEdges(topologyIdVersionIdQueryParams);
    for (TopologyEdge edge : edges) {
        addTopologyEdge(topologyId, newVersionId, new TopologyEdge(edge));
    }
    // add topology test run case
    Collection<TopologyTestRunCase> runCases = listTopologyTestRunCase(topologyIdVersionIdQueryParams);
    for (TopologyTestRunCase runCase : runCases) {
        Collection<TopologyTestRunCaseSource> runCaseSources = listTopologyTestRunCaseSource(runCase.getId());
        Collection<TopologyTestRunCaseSink> runCaseSinks = listTopologyTestRunCaseSink(runCase.getId());
        TopologyTestRunCase newCase = addTopologyTestRunCase(topologyId, newVersionId, new TopologyTestRunCase(runCase));
        // add topology test run case source
        for (TopologyTestRunCaseSource runCaseSource : runCaseSources) {
            addTopologyTestRunCaseSource(newCase.getId(), newVersionId, new TopologyTestRunCaseSource(runCaseSource));
        }
        // add topology test run case sink
        for (TopologyTestRunCaseSink runCaseSink : runCaseSinks) {
            addTopologyTestRunCaseSink(newCase.getId(), newVersionId, new TopologyTestRunCaseSink(runCaseSink));
        }
    }
}
Also used : TopologyWindow(com.hortonworks.streamline.streams.catalog.TopologyWindow) TopologySink(com.hortonworks.streamline.streams.catalog.TopologySink) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologySource(com.hortonworks.streamline.streams.catalog.TopologySource) TopologyEditorMetadata(com.hortonworks.streamline.streams.catalog.TopologyEditorMetadata) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyEdge(com.hortonworks.streamline.streams.catalog.TopologyEdge) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor)

Example 5 with TopologyBranchRule

use of com.hortonworks.streamline.streams.catalog.TopologyBranchRule in project streamline by hortonworks.

the class StreamCatalogService method parseAndSerialize.

private String parseAndSerialize(TopologyBranchRule ruleInfo) throws JsonProcessingException {
    Rule rule = new Rule();
    rule.setId(ruleInfo.getId());
    rule.setName(ruleInfo.getName());
    rule.setDescription(ruleInfo.getDescription());
    rule.setActions(ruleInfo.getActions());
    String sql = getSqlString(Collections.singletonList(ruleInfo.getStream()), null, ruleInfo.getCondition(), null);
    updateRuleWithSql(rule, sql, ruleInfo.getTopologyId(), ruleInfo.getVersionId());
    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(rule);
}
Also used : Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)12 Timed (com.codahale.metrics.annotation.Timed)5 TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)5 Path (javax.ws.rs.Path)5 TopologyWindow (com.hortonworks.streamline.streams.catalog.TopologyWindow)4 QueryParam (com.hortonworks.registries.common.QueryParam)3 StorableKey (com.hortonworks.registries.storage.StorableKey)3 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)3 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)3 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)3 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)3 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)3 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TopologyEdge (com.hortonworks.streamline.streams.catalog.TopologyEdge)2 TopologyProcessor (com.hortonworks.streamline.streams.catalog.TopologyProcessor)2 TopologySink (com.hortonworks.streamline.streams.catalog.TopologySink)2 TopologySource (com.hortonworks.streamline.streams.catalog.TopologySource)2 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)2 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)2