Skip to content

Commit

Permalink
HWKALERTS-40 Minor fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed May 28, 2015
1 parent 1fd3783 commit 8a25b92
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public interface DefinitionsService {
* Get a stored Trigger for a specific Tenant.
* @param tenantId Tenant where trigger is stored
* @param triggerId Given trigger to be retrieved
* @throws Exception
* @throws Exception on any problem
*/
Trigger getTrigger(String tenantId, String triggerId) throws Exception;

/**
* Get all stored Triggers for a specific Tenant.
* @param tenantId Tenant where triggers are stored
* @throws Exception
* @throws Exception on any problem
*/
Collection<Trigger> getTriggers(String tenantId) throws Exception;

/**
* Get all stored Triggers for all Tenants
* @throws Exception
* @throws Exception on any problem
*/
Collection<Trigger> getAllTriggers() throws Exception;

Expand Down Expand Up @@ -126,14 +126,14 @@ Collection<Dampening> getTriggerDampenings(String tenantId, String triggerId, Tr

/**
* @return The existing dampenings stored under a tenant
* @throws Exception
* @throws Exception on any problem
*/
Collection<Dampening> getAllDampenings() throws Exception;

/**
* @param tenantId Tenant where dampening are stored
* @return The existing dampenings stored under a tenant
* @throws Exception
* @throws Exception on any problem
*/
Collection<Dampening> getDampenings(String tenantId) throws Exception;

Expand Down Expand Up @@ -252,7 +252,7 @@ Collection<Condition> getTriggerConditions(String tenantId, String triggerId, Tr
* @param actionPlugin Action plugin where this action is stored
* @param actionId Id of new action
* @param properties the properties of the action
* @throws Exception
* @throws Exception on any problem
*/
void addAction(String tenantId, String actionPlugin, String actionId, Map<String, String> properties)
throws Exception;
Expand All @@ -264,14 +264,14 @@ void updateAction(String tenantId, String actionPlugin, String actionId, Map<Str

/**
* @return Map where key is a tenantId and value is a Map with actionPlugin as key and a set of actionsId as value
* @throws Exception
* @throws Exception on any problem
*/
Map<String, Map<String, Set<String>>> getAllActions() throws Exception;

/**
* @param tenantId Tenant where actions are stored.
* @return Map where key represents an actionPlugin and value a Set of actionsId per actionPlugin
* @throws Exception
* @throws Exception on any problem
*/
Map<String, Set<String>> getActions(String tenantId) throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import org.hawkular.alerts.api.model.condition.Alert;
Expand Down Expand Up @@ -179,6 +180,13 @@ public void initServices() {
}
}

@PreDestroy
public void shutdown() {
if (session != null) {
session.close();
}
}

private void initPreparedStatements() throws Exception {
if (insertAlert == null) {
insertAlert = session.prepare("INSERT INTO " + keyspace + ".alerts " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.naming.InitialContext;
import javax.naming.NamingException;
Expand Down Expand Up @@ -195,6 +196,13 @@ public void init() {
}
}

@PreDestroy
public void shutdown() {
if (session != null) {
session.close();
}
}

private void initialData() throws IOException {
String data = System.getProperty(JBOSS_DATA_DIR);
if (data == null || data.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TriggersITest extends AbstractITestBase {
assertEquals(200, resp.status)

resp = client.get(path: "triggers/test-trigger-1/tags");
assertEquals(404, resp.status)
assertEquals(204, resp.status)

resp = client.delete(path: "triggers/test-trigger-1")
assertEquals(200, resp.status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public Response findActions() {
notes = "Pagination is not yet implemented")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Actions Found"),
@ApiResponse(code = 404, message = "No Actions Found"),
@ApiResponse(code = 204, message = "No Actions Found"),
@ApiResponse(code = 500, message = "Internal server error") })
public Response findActionsByPlugin(@ApiParam(value = "Action plugin to filter query for action ids",
required = true)
Expand All @@ -136,7 +136,7 @@ public Response findActionsByPlugin(@ApiParam(value = "Action plugin to filter q
Collection<String> actions = definitions.getActions(persona.getId(), actionPlugin);
log.debugf("Actions: %s ", actions);
if (isEmpty(actions)) {
return ResponseUtil.notFound("No actions found for actionPlugin: " + actionPlugin + " ");
return ResponseUtil.noContent();
}
return ResponseUtil.ok(actions);
} catch (Exception e) {
Expand Down Expand Up @@ -232,7 +232,7 @@ public Response getAction(@ApiParam(value = "Action plugin", required = true)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Action Updated"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") })
@ApiResponse(code = 404, message = "Action not found for update") })
public Response updateAction(@ApiParam(value = "Action plugin", required = true)
@PathParam("actionPlugin")
final String actionPlugin,
Expand All @@ -250,7 +250,7 @@ public Response updateAction(@ApiParam(value = "Action plugin", required = true)
log.debugf("ActionId: %s - Properties: %s ", actionId, actionProperties);
return ResponseUtil.ok(actionProperties);
} else {
return ResponseUtil.badRequest("ActionId: " + actionId + " not found for update");
return ResponseUtil.notFound("ActionId: " + actionId + " not found for update");
}
} catch (Exception e) {
log.debugf(e.getMessage(), e);
Expand All @@ -264,7 +264,7 @@ public Response updateAction(@ApiParam(value = "Action plugin", required = true)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Action Deleted"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") })
@ApiResponse(code = 404, message = "ActionId not found for delete") })
public Response deleteAction(@ApiParam(value = "Action plugin", required = true)
@PathParam("actionPlugin")
final String actionPlugin,
Expand All @@ -280,7 +280,7 @@ public Response deleteAction(@ApiParam(value = "Action plugin", required = true)
log.debugf("ActionId: %s ", actionId);
return ResponseUtil.ok();
} else {
return ResponseUtil.badRequest("ActionId: " + actionId + " not found for delete");
return ResponseUtil.notFound("ActionId: " + actionId + " not found for delete");
}
} catch (Exception e) {
log.debugf(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Response createTrigger(@ApiParam(value = "Trigger definition to be create
return ResponseUtil.badRequest("Trigger with ID [" + trigger.getId() + "] exists.");
}
definitions.addTrigger(persona.getId(), trigger);
log.debugf("Trigger: %s ", trigger);
log.debugf("Trigger: %s ", trigger.toString());
return ResponseUtil.ok(trigger);
} else {
return ResponseUtil.badRequest("Trigger is null");
Expand Down Expand Up @@ -179,7 +179,7 @@ public Response getTrigger(@ApiParam(value = "Trigger definition id to be retrie
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Trigger updated"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 400, message = "Trigger doesn't exist/Invalid Parameters") })
@ApiResponse(code = 404, message = "Trigger doesn't exist/Invalid Parameters") })
public Response updateTrigger(@ApiParam(value = "Trigger definition id to be updated", required = true)
@PathParam("triggerId")
final String triggerId,
Expand All @@ -199,7 +199,7 @@ public Response updateTrigger(@ApiParam(value = "Trigger definition id to be upd
log.debugf("Trigger: %s ", trigger);
return ResponseUtil.ok();
} else {
return ResponseUtil.badRequest("Trigger " + triggerId + " doesn't exist for update");
return ResponseUtil.notFound("Trigger " + triggerId + " doesn't exist for update");
}
} catch (Exception e) {
log.debugf(e.getMessage(), e);
Expand Down Expand Up @@ -240,7 +240,7 @@ public Response deleteTrigger(@ApiParam(value = "Trigger definition id to be del
@ApiOperation(value = "Get all Dampenings for a Trigger (1 Dampening per mode).")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Dampenings found"),
@ApiResponse(code = 404, message = "No Dampenings found for trigger."),
@ApiResponse(code = 204, message = "No Dampenings found for trigger."),
@ApiResponse(code = 500, message = "Internal server error")})
public Response getTriggerDampenings(@ApiParam(value = "Trigger definition id to be retrieved", required = true)
@PathParam("triggerId")
Expand All @@ -252,7 +252,7 @@ public Response getTriggerDampenings(@ApiParam(value = "Trigger definition id to
Collection<Dampening> dampenings = definitions.getTriggerDampenings(persona.getId(), triggerId, null);
log.debugf("Dampenings: %s ", dampenings);
if (dampenings.isEmpty()) {
return ResponseUtil.notFound("No dampenings found for triggerId: " + triggerId);
return ResponseUtil.noContent();
}
return ResponseUtil.ok(dampenings);
} catch (Exception e) {
Expand All @@ -267,7 +267,7 @@ public Response getTriggerDampenings(@ApiParam(value = "Trigger definition id to
@ApiOperation(value = "Get a dampening using triggerId and triggerMode")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Dampening found"),
@ApiResponse(code = 404, message = "No Dampening found for triggerId/triggerMode"),
@ApiResponse(code = 204, message = "No Dampening found for triggerId/triggerMode"),
@ApiResponse(code = 500, message = "Internal server error") })
public Response getTriggerModeDampenings(@ApiParam(value = "Trigger definition id to be retrieved", required = true)
@PathParam("triggerId")
Expand All @@ -283,8 +283,7 @@ public Response getTriggerModeDampenings(@ApiParam(value = "Trigger definition i
triggerMode);
log.debugf("Dampenings: %s ", dampenings);
if (dampenings.isEmpty()) {
return ResponseUtil.notFound("No Dampening found for triggerId: " + triggerId + " triggerMode: " +
triggerMode);
return ResponseUtil.noContent();
}
return ResponseUtil.ok(dampenings);
} catch (Exception e) {
Expand Down Expand Up @@ -458,7 +457,7 @@ public Response deleteDampening(@ApiParam(value = "Trigger definition id to be r
@ApiOperation(value = "Get a map with all conditions for a specific trigger.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Conditions found"),
@ApiResponse(code = 404, message = "Success, no Conditions found"),
@ApiResponse(code = 204, message = "Success, no Conditions found"),
@ApiResponse(code = 500, message = "Internal server error") })
public Response getTriggerConditions(@ApiParam(value = "Trigger definition id to be retrieved", required = true)
@PathParam("triggerId")
Expand All @@ -470,7 +469,7 @@ public Response getTriggerConditions(@ApiParam(value = "Trigger definition id to
Collection<Condition> conditions = definitions.getTriggerConditions(persona.getId(), triggerId, null);
log.debugf("Conditions: %s ", conditions);
if (isEmpty(conditions)) {
return ResponseUtil.notFound("No conditions found for triggerId: " + triggerId);
return ResponseUtil.noContent();
}
return ResponseUtil.ok(conditions);
} catch (Exception e) {
Expand Down Expand Up @@ -763,7 +762,7 @@ public Response deleteTags(@ApiParam(value = "Trigger id of tags to be deleted",
response = Tag.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success, Tags found"),
@ApiResponse(code = 404, message = "No Tags found"),
@ApiResponse(code = 204, message = "No Tags found"),
@ApiResponse(code = 500, message = "Internal server error"),
@ApiResponse(code = 400, message = "Bad Request/Invalid Parameters") })
public Response getTriggerTags(@ApiParam(value = "Trigger id for the retrieved Tags", required = true)
Expand All @@ -779,8 +778,7 @@ public Response getTriggerTags(@ApiParam(value = "Trigger id for the retrieved T
Collection<Tag> tags = definitions.getTriggerTags(persona.getId(), triggerId, category);
log.debugf("Tags: " + tags);
if (isEmpty(tags)) {
return ResponseUtil.notFound("No tags found for triggerId: " + triggerId + " and category: " +
category);
return ResponseUtil.noContent();
}
return ResponseUtil.ok(tags);
} catch (Exception e) {
Expand Down

0 comments on commit 8a25b92

Please sign in to comment.