Skip to content

Commit

Permalink
Rename AlertsDefinitions per Definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasponce committed Feb 9, 2016
1 parent 56228d0 commit ce2f607
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@
* @author Jay Shaughnessy
* @author Lucas Ponce
*/
public class AlertDefinitions {
public class Definitions {

@JsonInclude(Include.NON_EMPTY)
private List<FullTrigger> triggers;

@JsonInclude(Include.NON_EMPTY)
private List<ActionDefinition> actions;

public AlertDefinitions() {
public Definitions() {
}

public AlertDefinitions(List<FullTrigger> triggers,
List<ActionDefinition> actions) {
public Definitions(List<FullTrigger> triggers,
List<ActionDefinition> actions) {
this.triggers = triggers;
this.actions = actions;
}
Expand All @@ -69,7 +69,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AlertDefinitions that = (AlertDefinitions) o;
Definitions that = (Definitions) o;

if (triggers != null ? !triggers.equals(that.triggers) : that.triggers != null) return false;
return actions != null ? actions.equals(that.actions) : that.actions == null;
Expand All @@ -84,7 +84,7 @@ public int hashCode() {

@Override
public String toString() {
return "AlertDefinitions" + '[' +
return "Definitions" + '[' +
"triggers=" + triggers +
", actions=" + actions +
']';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@
public enum ImportType {
/**
* Existing data in the backend is DELETED before the import operation.
* All FullTrigger and ActionDefinition objects defined in the AlertDefinitions parameter are imported.
* All FullTrigger and ActionDefinition objects defined in the Definitions parameter are imported.
*/
DELETE,

/**
* Existing data in the backend is NOT DELETED before the import operation.
* All FullTrigger and ActionDefinition objects defined in the AlertDefinitions parameter are imported.
* All FullTrigger and ActionDefinition objects defined in the Definitions parameter are imported.
* Existing FullTrigger and ActionDefinition objects are overwritten with new values passed in the
* AlertDefinitions parameter.
* Definitions parameter.
*/
ALL,

/**
* Existing data in the backend is NOT DELETED before the import operation.
* Only NEW FullTrigger and ActionDefinition objects defined in the AlertDefinitions parameters are imported.
* Only NEW FullTrigger and ActionDefinition objects defined in the Definitions parameters are imported.
* Existing FullTrigger and ActionDefinition objects are maintained in the backend.
*/
NEW,

/**
* Existing data in the backend is NOT DELETED before the import operation.
* Only FullTrigger and ActionDefinition objects defined in the AlertDefinitions parameter that previosly exist
* Only FullTrigger and ActionDefinition objects defined in the Definitions parameter that previously exist
* in the backend are imported and overwritten.
* New FullTrigger and ActionDefinition objects that don't exist previously in the backend are ignored.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.hawkular.alerts.api.model.action.ActionDefinition;
import org.hawkular.alerts.api.model.condition.Condition;
import org.hawkular.alerts.api.model.dampening.Dampening;
import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.model.export.ImportType;
import org.hawkular.alerts.api.model.paging.Page;
import org.hawkular.alerts.api.model.paging.Pager;
Expand Down Expand Up @@ -649,27 +649,27 @@ void updateActionPlugin(String actionPlugin, Map<String, String> defaultProperti

/**
* Export alert definitions per a specific Tenant.
* Alert definitions are wrapped in a AlertDefinitions object, which is a collection of FullTrigger (a Trigger
* Alert definitions are wrapped in a Definitions object, which is a collection of FullTrigger (a Trigger
* with Dampenings and Conditions) objects and a collection of ActionDefinition objects.
*
* @param tenantId Tenant where definitions are stored
* @return AlertDefinitions object with full triggers and actions definitions specified by tenantId
* @return Definitions object with full triggers and actions definitions specified by tenantId
* @throws Exception on any problem
*/
AlertDefinitions exportDefinitions(String tenantId) throws Exception;
Definitions exportDefinitions(String tenantId) throws Exception;

/**
* Import alert definitions per a specific Tenant.
* Alert definitions are wrapped in an AlertDefinitions object, which contains a collection of FullTrigger (a
* Alert definitions are wrapped in an Definitions object, which contains a collection of FullTrigger (a
* Trigger with Dampenings and Conditions) objects and a collection of ActionDefinition objects.
* An ImportType stragy must be defined to resolve conflicts with existing data.
*
* @param tenantId Tenant where definitions will be imported
* @param alertDefinitions AlertDefinitions with the collections of FullTrigger and ActionDefinition to import
* @param definitions Definitions with the collections of FullTrigger and ActionDefinition to import
* @param strategy the ImportType strategy to apply
* @return an ActionDefinition object updated with the effective FullTrigger and ActionDefinition imported
* @throws Exception on any problem
*/
AlertDefinitions importDefinitions(String tenantId, AlertDefinitions alertDefinitions, ImportType strategy)
Definitions importDefinitions(String tenantId, Definitions definitions, ImportType strategy)
throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;

import org.hawkular.alerts.api.model.action.ActionDefinition;
import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.model.trigger.FullTrigger;
import org.jboss.logging.Logger;

Expand All @@ -35,7 +35,7 @@
public class AlertsImportManager {
private static final Logger log = Logger.getLogger(AlertsImportManager.class);
private ObjectMapper objectMapper = new ObjectMapper();
private AlertDefinitions alertDefinitions;
private Definitions definitions;

/**
* Read a json file and initialize the AlertsImportManager instance
Expand All @@ -51,22 +51,22 @@ public AlertsImportManager(File fAlerts) throws Exception {
throw new IllegalArgumentException(fAlerts.getName() + " file must exist");
}

alertDefinitions = objectMapper.readValue(fAlerts, AlertDefinitions.class);
definitions = objectMapper.readValue(fAlerts, Definitions.class);
if (log.isDebugEnabled()) {
if (alertDefinitions != null) {
log.debug("File: " + fAlerts.toString() + " imported in " + alertDefinitions.toString());
if (definitions != null) {
log.debug("File: " + fAlerts.toString() + " imported in " + definitions.toString());
} else {
log.debug("File: " + fAlerts.toString() + " imported is null");
}
}
}

public List<FullTrigger> getFullTriggers() {
return (alertDefinitions != null ? alertDefinitions.getTriggers() : null);
return (definitions != null ? definitions.getTriggers() : null);
}

public List<ActionDefinition> getActionDefinitions() {
return (alertDefinitions != null ? alertDefinitions.getActions() : null);
return (definitions != null ? definitions.getActions() : null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.hawkular.alerts.api.model.dampening.Dampening;
import org.hawkular.alerts.api.model.data.Data;
import org.hawkular.alerts.api.model.event.EventType;
import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.model.export.ImportType;
import org.hawkular.alerts.api.model.paging.Order;
import org.hawkular.alerts.api.model.paging.Page;
Expand Down Expand Up @@ -2852,34 +2852,34 @@ private void notifyListeners(Type eventType) {
}

@Override
public AlertDefinitions exportDefinitions(String tenantId) throws Exception {
public Definitions exportDefinitions(String tenantId) throws Exception {
if (isEmpty(tenantId)) {
throw new IllegalArgumentException("TenantId must be not null");
}
AlertDefinitions alertDefinitions = new AlertDefinitions();
Definitions definitions = new Definitions();
try {
alertDefinitions.setTriggers(getFullTriggers(tenantId));
alertDefinitions.setActions(getActionDefinitions(tenantId));
definitions.setTriggers(getFullTriggers(tenantId));
definitions.setActions(getActionDefinitions(tenantId));
} catch (Exception e) {
msgLog.errorDatabaseException(e.getMessage());
throw e;
}
return alertDefinitions;
return definitions;
}

@Override
public AlertDefinitions importDefinitions(String tenantId, AlertDefinitions alertDefinitions, ImportType strategy)
public Definitions importDefinitions(String tenantId, Definitions definitions, ImportType strategy)
throws Exception {
if (isEmpty(tenantId)) {
throw new IllegalArgumentException("TenantId must be not null");
}
if (null == alertDefinitions) {
throw new IllegalArgumentException("AlertDefinitions must be not null");
if (null == definitions) {
throw new IllegalArgumentException("Definitions must be not null");
}
if (null == strategy) {
throw new IllegalArgumentException("ImportType startegy must be not null");
}
AlertDefinitions imported = new AlertDefinitions();
Definitions imported = new Definitions();
try {
Collection<Trigger> existingTriggers = selectTriggers(tenantId);
Map<String, Set<String>> existingDefinitions = getActionDefinitionIds(tenantId);
Expand All @@ -2896,8 +2896,8 @@ public AlertDefinitions importDefinitions(String tenantId, AlertDefinitions aler
}
}
List<FullTrigger> importedTriggers = new ArrayList<>();
if (!isEmpty(alertDefinitions.getTriggers())) {
for (FullTrigger t : alertDefinitions.getTriggers()) {
if (!isEmpty(definitions.getTriggers())) {
for (FullTrigger t : definitions.getTriggers()) {
if (!isEmpty(t.getTrigger())) {
boolean existing = existingTriggers.contains(t.getTrigger());
switch (strategy) {
Expand Down Expand Up @@ -2934,8 +2934,8 @@ public AlertDefinitions importDefinitions(String tenantId, AlertDefinitions aler
}
}
List<ActionDefinition> importedActionDefinitions = new ArrayList<>();
if (!isEmpty(alertDefinitions.getActions())) {
for (ActionDefinition a : alertDefinitions.getActions()) {
if (!isEmpty(definitions.getActions())) {
for (ActionDefinition a : definitions.getActions()) {
a.setTenantId(tenantId);
if (!isEmpty(a)) {
boolean existing = existingDefinitions.containsKey(a.getActionPlugin()) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.hawkular.alerts.api.model.event.Alert;
import org.hawkular.alerts.api.model.event.Event;
import org.hawkular.alerts.api.model.event.EventCategory;
import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.model.export.ImportType;
import org.hawkular.alerts.api.model.paging.ActionComparator;
import org.hawkular.alerts.api.model.paging.AlertComparator;
Expand Down Expand Up @@ -105,7 +105,7 @@ public void test000InitScheme() throws Exception {
public void test001ExportImport() throws Exception {
logger.info("test001ExportDefinitions");

AlertDefinitions exported = definitionsService.exportDefinitions(TENANT);
Definitions exported = definitionsService.exportDefinitions(TENANT);
int exportedTriggers = exported.getTriggers().size();
int exportedActionDefinitions = exported.getActions().size();
assertTrue(exportedTriggers > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.rest.ResponseUtil.ApiError;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -58,15 +58,15 @@ public class ExportHandler {
@Path("/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Export a list of full triggers and action definitions.",
response = AlertDefinitions.class)
response = Definitions.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully exported list of full triggers and action definitions."),
@ApiResponse(code = 500, message = "Internal server error.", response = ApiError.class)
})
public Response exportDefinitions() {
try {
AlertDefinitions alertDefinitions = definitions.exportDefinitions(tenantId);
return ResponseUtil.ok(alertDefinitions);
Definitions definitions = this.definitions.exportDefinitions(tenantId);
return ResponseUtil.ok(definitions);
} catch (Exception e) {
log.debug(e.getMessage(), e);
return ResponseUtil.internalError(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.hawkular.alerts.api.model.export.AlertDefinitions;
import org.hawkular.alerts.api.model.export.Definitions;
import org.hawkular.alerts.api.model.export.ImportType;
import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.rest.ResponseUtil.ApiError;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class ImportHandler {
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Import a list of full triggers and action definitions.",
notes = "Return a list of effectively imported full triggers and action definitions.",
response = AlertDefinitions.class)
response = Definitions.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully exported list of full triggers and action definitions."),
@ApiResponse(code = 500, message = "Internal server error.", response = ApiError.class),
Expand All @@ -73,10 +73,10 @@ public Response importDefinitions(
@PathParam("strategy")
final String strategy,
@ApiParam(value = "Collection of full triggers and action definitions to import.")
final AlertDefinitions alertDefinitions) {
final Definitions definitions) {
try {
ImportType importType = ImportType.valueOf(strategy.toUpperCase());
AlertDefinitions imported = definitions.importDefinitions(tenantId, alertDefinitions, importType);
Definitions imported = this.definitions.importDefinitions(tenantId, definitions, importType);
return ResponseUtil.ok(imported);
} catch (IllegalArgumentException e) {
return ResponseUtil.badRequest("Bad argument: " + e.getMessage());
Expand Down

0 comments on commit ce2f607

Please sign in to comment.