use of com.hortonworks.streamline.streams.catalog.TopologyRule in project streamline by hortonworks.
the class RuleCatalogResource method addOrUpdateRule.
/**
* <p>Updates a topology rule.</p>
* <p>
* <b>PUT /api/v1/catalog/topologies/:TOPOLOGY_ID/rules/:RULE_ID</b>
* <pre>
* {
* "name": "rule1",
* "description": "rule test",
* "sql": "select temperature, celciusToFarenheit(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, celciusToFarenheit(temperature), humidity from nest where humidity > 90 AND celciusToFarenheit(temperature) > 80",
* "window": null,
* "actions": ...
* }
* }
* </pre>
*/
@PUT
@Path("/topologies/{topologyId}/rules/{id}")
@Timed
public Response addOrUpdateRule(@PathParam("topologyId") Long topologyId, @PathParam("id") Long ruleId, TopologyRule topologyRule, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_SUPER_ADMIN, Topology.NAMESPACE, topologyId, WRITE);
TopologyRule createdTopologyRule = catalogService.addOrUpdateRule(topologyId, ruleId, topologyRule);
return WSUtils.respondEntity(createdTopologyRule, CREATED);
}
use of com.hortonworks.streamline.streams.catalog.TopologyRule in project streamline by hortonworks.
the class RuleCatalogResource method getTopologyRuleByIdAndVersion.
@GET
@Path("/topologies/{topologyId}/versions/{versionId}/rules/{id}")
@Timed
public Response getTopologyRuleByIdAndVersion(@PathParam("topologyId") Long topologyId, @PathParam("id") Long ruleId, @PathParam("versionId") Long versionId, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
TopologyRule topologyRule = catalogService.getRule(topologyId, ruleId, versionId);
if (topologyRule != null) {
return WSUtils.respondEntity(topologyRule, OK);
}
throw EntityNotFoundException.byVersion(buildMessageForCompositeId(topologyId, ruleId), versionId.toString());
}
use of com.hortonworks.streamline.streams.catalog.TopologyRule in project streamline by hortonworks.
the class RuleCatalogResource method getTopologyRuleById.
/**
* <p>
* Gets a specific rule by Id. For example,
* </p>
* <b>GET /api/v1/catalog/topologies/:TOPOLOGY_ID/rules/:RULE_ID</b>
* <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>
*/
@GET
@Path("/topologies/{topologyId}/rules/{id}")
@Timed
public Response getTopologyRuleById(@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);
TopologyRule topologyRule = catalogService.getRule(topologyId, ruleId);
if (topologyRule != null) {
return WSUtils.respondEntity(topologyRule, OK);
}
throw EntityNotFoundException.byId(buildMessageForCompositeId(topologyId, ruleId));
}
use of com.hortonworks.streamline.streams.catalog.TopologyRule in project streamline by hortonworks.
the class RuleCatalogResource method removeRule.
/**
* <p>
* Removes a rule.
* </p>
* <b>DELETE /api/v1/catalog/topologies/:TOPOLOGY_ID/rules/:RULE_ID</b>
* <pre>
* {
* "responseCode": 1000,
* "responseMessage": "Success",
* "entity": {
* "id": 1,
* "topologyId": 1,
* "name": "rule1",
* "description": "rule test",
* "sql": "select temperature, celciusToFarenheit(temperature), humidity from nest where humidity > 90 AND celciusToFarenheit(temperature) > 80",
* "window": null,
* "actions": ...
* }
* }
* </pre>
*/
@DELETE
@Path("/topologies/{topologyId}/rules/{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);
TopologyRule topologyRule = catalogService.removeRule(topologyId, ruleId);
if (topologyRule != null) {
return WSUtils.respondEntity(topologyRule, OK);
}
throw EntityNotFoundException.byId(ruleId.toString());
}
use of com.hortonworks.streamline.streams.catalog.TopologyRule 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));
}
}
}
Aggregations