use of org.apache.nifi.web.NiFiWebConfigurationRequestContext in project nifi by apache.
the class ProcessorResource method setProperties.
@PUT
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@Path("/properties")
public Response setProperties(@QueryParam("processorId") final String processorId, @QueryParam("revisionId") final Long revisionId, @QueryParam("clientId") final String clientId, Map<String, String> properties) {
final NiFiWebConfigurationContext nifiWebContext = getWebConfigurationContext();
final NiFiWebConfigurationRequestContext niFiRequestContext = ProcessorWebUtils.getRequestContext(processorId, revisionId, clientId, request);
final ComponentDetails componentDetails = nifiWebContext.updateComponent(niFiRequestContext, null, properties);
final Response.ResponseBuilder response = ProcessorWebUtils.applyCacheControl(Response.ok(componentDetails));
return response.build();
}
use of org.apache.nifi.web.NiFiWebConfigurationRequestContext in project nifi by apache.
the class RuleResource method updateEvaluationContext.
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/evaluation-context")
public Response updateEvaluationContext(@Context final UriInfo uriInfo, final EvaluationContextEntity requestEntity) {
// get the web context
final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
// ensure the evaluation context has been specified
if (requestEntity == null) {
throw new WebApplicationException(badRequest("The evaluation context must be specified."));
}
// ensure the id has been specified
if (requestEntity.getRuleOrder() == null && requestEntity.getFlowFilePolicy() == null) {
throw new WebApplicationException(badRequest("Either the rule order or the matching strategy must be specified."));
}
// build the web context config
final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(requestEntity.getProcessorId(), requestEntity.getRevision(), requestEntity.getClientId());
// load the criteria
final Criteria criteria = getCriteria(configurationContext, requestContext);
// if a new rule order is specified, attempt to set it
if (requestEntity.getRuleOrder() != null) {
try {
criteria.reorder(requestEntity.getRuleOrder());
} catch (final IllegalArgumentException iae) {
throw new WebApplicationException(iae, badRequest(iae.getMessage()));
}
}
// if a new matching strategy is specified, attempt to set it
if (requestEntity.getFlowFilePolicy() != null) {
try {
criteria.setFlowFilePolicy(FlowFilePolicy.valueOf(requestEntity.getFlowFilePolicy()));
} catch (final IllegalArgumentException iae) {
throw new WebApplicationException(iae, badRequest("The specified matching strategy is unknown: " + requestEntity.getFlowFilePolicy()));
}
}
// save the criteria
saveCriteria(requestContext, criteria);
// create the response entity
final EvaluationContextEntity responseEntity = new EvaluationContextEntity();
responseEntity.setClientId(requestEntity.getClientId());
responseEntity.setRevision(requestEntity.getRevision());
responseEntity.setProcessorId(requestEntity.getProcessorId());
responseEntity.setFlowFilePolicy(criteria.getFlowFilePolicy().name());
responseEntity.setRuleOrder(criteria.getRuleOrder());
// generate the response
final ResponseBuilder response = Response.ok(responseEntity);
return noCache(response).build();
}
use of org.apache.nifi.web.NiFiWebConfigurationRequestContext in project nifi by apache.
the class RuleResource method updateRule.
@PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/{id}")
public Response updateRule(@Context final UriInfo uriInfo, @PathParam("id") final String ruleId, final RuleEntity requestEntity) {
// get the web context
final NiFiWebConfigurationContext nifiWebContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
// ensure the rule has been specified
if (requestEntity == null || requestEntity.getRule() == null) {
throw new WebApplicationException(badRequest("The rule must be specified."));
}
final RuleDTO ruleDto = requestEntity.getRule();
// ensure the id has been specified
if (ruleDto.getId() == null) {
throw new WebApplicationException(badRequest("The rule id must be specified."));
}
if (!ruleDto.getId().equals(ruleId)) {
throw new WebApplicationException(badRequest("The rule id in the path does not equal the rule id in the request body."));
}
// ensure the rule name was specified
if (ruleDto.getName() == null || ruleDto.getName().isEmpty()) {
throw new WebApplicationException(badRequest("The rule name must be specified and cannot be blank."));
}
// ensure there are some conditions
if (ruleDto.getConditions() == null || ruleDto.getConditions().isEmpty()) {
throw new WebApplicationException(badRequest("The rule conditions must be set."));
}
// ensure there are some actions
if (ruleDto.getActions() == null || ruleDto.getActions().isEmpty()) {
throw new WebApplicationException(badRequest("The rule actions must be set."));
}
// build the web context config
final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(requestEntity.getProcessorId(), requestEntity.getRevision(), requestEntity.getClientId());
// load the criteria
final UpdateAttributeModelFactory factory = new UpdateAttributeModelFactory();
final Criteria criteria = getCriteria(nifiWebContext, requestContext);
// attempt to locate the rule
Rule rule = criteria.getRule(ruleId);
// if the rule isn't found add it
boolean newRule = false;
if (rule == null) {
newRule = true;
rule = new Rule();
rule.setId(ruleId);
}
try {
// evaluate the conditions and actions before modifying the rule
final Set<Condition> conditions = factory.createConditions(ruleDto.getConditions());
final Set<Action> actions = factory.createActions(ruleDto.getActions());
// update the rule
rule.setName(ruleDto.getName());
rule.setConditions(conditions);
rule.setActions(actions);
} catch (final IllegalArgumentException iae) {
throw new WebApplicationException(iae, badRequest(iae.getMessage()));
}
// add the new rule if application
if (newRule) {
criteria.addRule(rule);
}
// save the criteria
saveCriteria(requestContext, criteria);
// create the response entity
final RuleEntity responseEntity = new RuleEntity();
responseEntity.setClientId(requestEntity.getClientId());
responseEntity.setRevision(requestEntity.getRevision());
responseEntity.setProcessorId(requestEntity.getProcessorId());
responseEntity.setRule(DtoFactory.createRuleDTO(rule));
// generate the response
final ResponseBuilder response;
if (newRule) {
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
response = Response.created(uriBuilder.path(ruleId).build()).entity(responseEntity);
} else {
response = Response.ok(responseEntity);
}
return noCache(response).build();
}
use of org.apache.nifi.web.NiFiWebConfigurationRequestContext in project nifi by apache.
the class RuleResource method createRule.
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules")
public Response createRule(@Context final UriInfo uriInfo, final RuleEntity requestEntity) {
// get the web context
final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
// ensure the rule has been specified
if (requestEntity == null || requestEntity.getRule() == null) {
throw new WebApplicationException(badRequest("The rule must be specified."));
}
final RuleDTO ruleDto = requestEntity.getRule();
// ensure the id hasn't been specified
if (ruleDto.getId() != null) {
throw new WebApplicationException(badRequest("The rule id cannot be specified."));
}
// ensure there are some conditions
if (ruleDto.getConditions() == null || ruleDto.getConditions().isEmpty()) {
throw new WebApplicationException(badRequest("The rule conditions must be set."));
}
// ensure there are some actions
if (ruleDto.getActions() == null || ruleDto.getActions().isEmpty()) {
throw new WebApplicationException(badRequest("The rule actions must be set."));
}
// generate a new id
final String uuid = UUID.randomUUID().toString();
// build the request context
final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(requestEntity.getProcessorId(), requestEntity.getRevision(), requestEntity.getClientId());
// load the criteria
final Criteria criteria = getCriteria(configurationContext, requestContext);
final UpdateAttributeModelFactory factory = new UpdateAttributeModelFactory();
// create the new rule
final Rule rule;
try {
rule = factory.createRule(ruleDto);
rule.setId(uuid);
} catch (final IllegalArgumentException iae) {
throw new WebApplicationException(iae, badRequest(iae.getMessage()));
}
// add the rule
criteria.addRule(rule);
// save the criteria
saveCriteria(requestContext, criteria);
// create the response entity
final RuleEntity responseEntity = new RuleEntity();
responseEntity.setClientId(requestEntity.getClientId());
responseEntity.setRevision(requestEntity.getRevision());
responseEntity.setProcessorId(requestEntity.getProcessorId());
responseEntity.setRule(DtoFactory.createRuleDTO(rule));
// generate the response
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
final ResponseBuilder response = Response.created(uriBuilder.path(uuid).build()).entity(responseEntity);
return noCache(response).build();
}
use of org.apache.nifi.web.NiFiWebConfigurationRequestContext in project nifi by apache.
the class RuleResource method deleteRule.
@DELETE
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Path("/rules/{id}")
public Response deleteRule(@PathParam("id") final String ruleId, @QueryParam("processorId") final String processorId, @QueryParam("clientId") final String clientId, @QueryParam("revision") final Long revision) {
// get the web context
final NiFiWebConfigurationContext configurationContext = (NiFiWebConfigurationContext) servletContext.getAttribute("nifi-web-configuration-context");
// build the web context config
final NiFiWebConfigurationRequestContext requestContext = getConfigurationRequestContext(processorId, revision, clientId);
// load the criteria and get the rule
final Criteria criteria = getCriteria(configurationContext, requestContext);
final Rule rule = criteria.getRule(ruleId);
if (rule == null) {
throw new NotFoundException();
}
// delete the rule
criteria.deleteRule(rule);
// save the criteria
saveCriteria(requestContext, criteria);
// create the response entity
final RulesEntity responseEntity = new RulesEntity();
responseEntity.setClientId(clientId);
responseEntity.setRevision(revision);
responseEntity.setProcessorId(processorId);
// generate the response
final ResponseBuilder response = Response.ok(responseEntity);
return noCache(response).build();
}
Aggregations