Search in sources :

Example 16 with TopologyRule

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

the class StreamCatalogService method getRule.

public TopologyRule getRule(Long topologyId, Long ruleId, Long versionId) {
    TopologyRule topologyTopologyRule = new TopologyRule();
    topologyTopologyRule.setId(ruleId);
    topologyTopologyRule.setVersionId(versionId);
    TopologyRule ruleInfo = dao.get(new StorableKey(TOPOLOGY_RULEINFO_NAMESPACE, topologyTopologyRule.getPrimaryKey()));
    if (ruleInfo == null || !ruleInfo.getTopologyId().equals(topologyId)) {
        return null;
    }
    ruleInfo.setVersionTimestamp(getVersionTimestamp(versionId));
    return ruleInfo;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule)

Example 17 with TopologyRule

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

the class StreamCatalogService method removeRule.

public TopologyRule removeRule(Long topologyId, Long ruleId, Long versionId) throws Exception {
    TopologyRule topologyRule = getRule(topologyId, ruleId, versionId);
    if (topologyRule != null) {
        topologyRule = dao.remove(new StorableKey(TOPOLOGY_RULEINFO_NAMESPACE, topologyRule.getPrimaryKey()));
        topologyRule.setVersionTimestamp(updateVersionTimestamp(versionId).getTimestamp());
    }
    return topologyRule;
}
Also used : StorableKey(com.hortonworks.registries.storage.StorableKey) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule)

Example 18 with TopologyRule

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

the class RuleCatalogResource method addTopologyRule.

/**
 * <p>
 * Creates a topology rule. For example,
 * </p>
 * <b>POST /api/v1/catalog/topologies/:TOPOLOGY_ID/rules</b>
 * <pre>
 * {
 *   "name": "rule1",
 *   "description": "rule test",
 *   "sql": "select temperature, humidity from nest where 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",
 *     "sql": "select temperature, humidity from nest where humidity > 90 AND celciusToFarenheit(temperature) > 80",
 *     "window": null,
 *     "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}/rules")
@Timed
public Response addTopologyRule(@PathParam("topologyId") Long topologyId, TopologyRule topologyRule, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, WRITE);
    TopologyRule createdTopologyRule = catalogService.addRule(topologyId, topologyRule);
    return WSUtils.respondEntity(createdTopologyRule, CREATED);
}
Also used : TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

TopologyRule (com.hortonworks.streamline.streams.catalog.TopologyRule)18 ArrayList (java.util.ArrayList)7 BaseTopologyRule (com.hortonworks.streamline.streams.catalog.BaseTopologyRule)6 TopologyStream (com.hortonworks.streamline.streams.catalog.TopologyStream)6 Expectations (mockit.Expectations)6 Test (org.junit.Test)6 Timed (com.codahale.metrics.annotation.Timed)5 TopologyBranchRule (com.hortonworks.streamline.streams.catalog.TopologyBranchRule)5 Stream (com.hortonworks.streamline.streams.layout.component.Stream)5 TopologyWindow (com.hortonworks.streamline.streams.catalog.TopologyWindow)4 UDF (com.hortonworks.streamline.streams.catalog.UDF)4 Path (javax.ws.rs.Path)4 QueryParam (com.hortonworks.registries.common.QueryParam)3 StorableKey (com.hortonworks.registries.storage.StorableKey)3 Rule (com.hortonworks.streamline.streams.layout.component.rule.Rule)3 BinaryExpression (com.hortonworks.streamline.streams.layout.component.rule.expression.BinaryExpression)3 Literal (com.hortonworks.streamline.streams.layout.component.rule.expression.Literal)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)2 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)2