Undo code changes / reformatting
This commit is contained in:
parent
2b13727344
commit
1b6d5653fc
|
@ -36,109 +36,109 @@ import java.util.Set;
|
|||
* @author Jonathan Halterman
|
||||
*/
|
||||
public class MonApiApplication extends Application<MonApiConfiguration> {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new MonApiApplication().run(args);
|
||||
public static void main(String[] args) throws Exception {
|
||||
new MonApiApplication().run(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Bootstrap<MonApiConfiguration> bootstrap) {
|
||||
/** Configure bundles */
|
||||
bootstrap.addBundle(new DBIExceptionsBundle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "HP Cloud Monitoring";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(MonApiConfiguration config, Environment environment) throws Exception {
|
||||
/** Wire services */
|
||||
Injector.registerModules(new MonApiModule(environment, config));
|
||||
|
||||
/** Configure resources */
|
||||
environment.jersey().register(Injector.getInstance(VersionResource.class));
|
||||
environment.jersey().register(Injector.getInstance(AlarmResource.class));
|
||||
environment.jersey().register(Injector.getInstance(MetricResource.class));
|
||||
environment.jersey().register(Injector.getInstance(MeasurementResource.class));
|
||||
environment.jersey().register(Injector.getInstance(StatisticResource.class));
|
||||
environment.jersey().register(Injector.getInstance(NotificationMethodResource.class));
|
||||
|
||||
/** Configure providers */
|
||||
removeExceptionMappers(environment.jersey().getResourceConfig().getSingletons());
|
||||
environment.jersey().register(new EntityExistsExceptionMapper());
|
||||
environment.jersey().register(new EntityNotFoundExceptionMapper());
|
||||
environment.jersey().register(new ResourceNotFoundExceptionMapper());
|
||||
environment.jersey().register(new IllegalArgumentExceptionMapper());
|
||||
environment.jersey().register(new InvalidEntityExceptionMapper());
|
||||
environment.jersey().register(new JsonProcessingExceptionMapper());
|
||||
environment.jersey().register(new JsonMappingExceptionManager());
|
||||
environment.jersey().register(new ConstraintViolationExceptionMapper());
|
||||
environment.jersey().register(new ThrowableExceptionMapper<Throwable>() {
|
||||
});
|
||||
|
||||
/** Configure Jackson */
|
||||
environment.getObjectMapper().setPropertyNamingStrategy(
|
||||
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
|
||||
environment.getObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
|
||||
|
||||
/** Configure health checks */
|
||||
environment.healthChecks().register("kafka", new KafkaHealthCheck(config.kafka));
|
||||
|
||||
/** Configure auth filters */
|
||||
if (config.middleware.enabled) {
|
||||
Map<String, String> authInitParams = new HashMap<String, String>();
|
||||
authInitParams.put("ServiceIds", config.middleware.serviceIds);
|
||||
authInitParams.put("EndpointIds", config.middleware.endpointIds);
|
||||
authInitParams.put("ServerVIP", config.middleware.serverVIP);
|
||||
authInitParams.put("ServerPort", config.middleware.serverPort);
|
||||
authInitParams.put("ConnTimeout", config.middleware.connTimeout);
|
||||
authInitParams.put("ConnSSLClientAuth", config.middleware.connSSLClientAuth);
|
||||
authInitParams.put("Keystore", config.middleware.keystore);
|
||||
authInitParams.put("KeystorePass", config.middleware.keystorePass);
|
||||
authInitParams.put("Truststore", config.middleware.truststore);
|
||||
authInitParams.put("TruststorePass", config.middleware.truststorePass);
|
||||
authInitParams.put("ConnPoolMaxActive", config.middleware.connPoolMaxActive);
|
||||
authInitParams.put("ConnPoolMaxIdle", config.middleware.connPoolMaxActive);
|
||||
authInitParams.put("ConnPoolEvictPeriod", config.middleware.connPoolEvictPeriod);
|
||||
authInitParams.put("ConnPoolMinIdleTime", config.middleware.connPoolMinIdleTime);
|
||||
authInitParams.put("ConnRetryTimes", config.middleware.connRetryTimes);
|
||||
authInitParams.put("ConnRetryInterval", config.middleware.connRetryInterval);
|
||||
|
||||
environment.servlets()
|
||||
.addFilter("pre-auth", new PreAuthenticationFilter())
|
||||
.addMappingForUrlPatterns(null, true, "/*");
|
||||
Dynamic filter = environment.servlets().addFilter("token-auth", new TokenAuth());
|
||||
filter.addMappingForUrlPatterns(null, true, "/*");
|
||||
filter.setInitParameters(authInitParams);
|
||||
environment.servlets()
|
||||
.addFilter("post-auth", new PostAuthenticationFilter(config.middleware.rolesToMatch))
|
||||
.addMappingForUrlPatterns(null, true, "/*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Bootstrap<MonApiConfiguration> bootstrap) {
|
||||
/** Configure bundles */
|
||||
bootstrap.addBundle(new DBIExceptionsBundle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "HP Cloud Monitoring";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(MonApiConfiguration config, Environment environment) throws Exception {
|
||||
/** Wire services */
|
||||
Injector.registerModules(new MonApiModule(environment, config));
|
||||
|
||||
/** Configure resources */
|
||||
environment.jersey().register(Injector.getInstance(VersionResource.class));
|
||||
environment.jersey().register(Injector.getInstance(AlarmResource.class));
|
||||
environment.jersey().register(Injector.getInstance(MetricResource.class));
|
||||
environment.jersey().register(Injector.getInstance(MeasurementResource.class));
|
||||
environment.jersey().register(Injector.getInstance(StatisticResource.class));
|
||||
environment.jersey().register(Injector.getInstance(NotificationMethodResource.class));
|
||||
|
||||
/** Configure providers */
|
||||
removeExceptionMappers(environment.jersey().getResourceConfig().getSingletons());
|
||||
environment.jersey().register(new EntityExistsExceptionMapper());
|
||||
environment.jersey().register(new EntityNotFoundExceptionMapper());
|
||||
environment.jersey().register(new ResourceNotFoundExceptionMapper());
|
||||
environment.jersey().register(new IllegalArgumentExceptionMapper());
|
||||
environment.jersey().register(new InvalidEntityExceptionMapper());
|
||||
environment.jersey().register(new JsonProcessingExceptionMapper());
|
||||
environment.jersey().register(new JsonMappingExceptionManager());
|
||||
environment.jersey().register(new ConstraintViolationExceptionMapper());
|
||||
environment.jersey().register(new ThrowableExceptionMapper<Throwable>() {
|
||||
});
|
||||
|
||||
/** Configure Jackson */
|
||||
environment.getObjectMapper().setPropertyNamingStrategy(
|
||||
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
|
||||
environment.getObjectMapper().enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
|
||||
|
||||
/** Configure health checks */
|
||||
environment.healthChecks().register("kafka", new KafkaHealthCheck(config.kafka));
|
||||
|
||||
/** Configure auth filters */
|
||||
if (config.middleware.enabled) {
|
||||
Map<String, String> authInitParams = new HashMap<String, String>();
|
||||
authInitParams.put("ServiceIds", config.middleware.serviceIds);
|
||||
authInitParams.put("EndpointIds", config.middleware.endpointIds);
|
||||
authInitParams.put("ServerVIP", config.middleware.serverVIP);
|
||||
authInitParams.put("ServerPort", config.middleware.serverPort);
|
||||
authInitParams.put("ConnTimeout", config.middleware.connTimeout);
|
||||
authInitParams.put("ConnSSLClientAuth", config.middleware.connSSLClientAuth);
|
||||
authInitParams.put("Keystore", config.middleware.keystore);
|
||||
authInitParams.put("KeystorePass", config.middleware.keystorePass);
|
||||
authInitParams.put("Truststore", config.middleware.truststore);
|
||||
authInitParams.put("TruststorePass", config.middleware.truststorePass);
|
||||
authInitParams.put("ConnPoolMaxActive", config.middleware.connPoolMaxActive);
|
||||
authInitParams.put("ConnPoolMaxIdle", config.middleware.connPoolMaxActive);
|
||||
authInitParams.put("ConnPoolEvictPeriod", config.middleware.connPoolEvictPeriod);
|
||||
authInitParams.put("ConnPoolMinIdleTime", config.middleware.connPoolMinIdleTime);
|
||||
authInitParams.put("ConnRetryTimes", config.middleware.connRetryTimes);
|
||||
authInitParams.put("ConnRetryInterval", config.middleware.connRetryInterval);
|
||||
|
||||
environment.servlets()
|
||||
.addFilter("pre-auth", new PreAuthenticationFilter())
|
||||
.addMappingForUrlPatterns(null, true, "/*");
|
||||
Dynamic filter = environment.servlets().addFilter("token-auth", new TokenAuth());
|
||||
filter.addMappingForUrlPatterns(null, true, "/*");
|
||||
filter.setInitParameters(authInitParams);
|
||||
environment.servlets()
|
||||
.addFilter("post-auth", new PostAuthenticationFilter(config.middleware.rolesToMatch))
|
||||
.addMappingForUrlPatterns(null, true, "/*");
|
||||
}
|
||||
|
||||
environment.jersey().register(new ApiListingResourceJSON());
|
||||
|
||||
// Swagger providers
|
||||
environment.jersey().register(new ApiDeclarationProvider());
|
||||
environment.jersey().register(new ResourceListingProvider());
|
||||
|
||||
// Swagger Scanner, which finds all the resources for @Api Annotations
|
||||
ScannerFactory.setScanner(new DefaultJaxrsScanner());
|
||||
|
||||
// Add the reader, which scans the resources and extracts the resource information
|
||||
ClassReaders.setReader(new DefaultJaxrsApiReader());
|
||||
|
||||
// Set the swagger config options
|
||||
SwaggerConfig swaggerConfig = ConfigFactory.config();
|
||||
swaggerConfig.setApiVersion("1.0.1");
|
||||
swaggerConfig.setBasePath("http://localhost:8000");
|
||||
}
|
||||
|
||||
private void removeExceptionMappers(Set<Object> items) {
|
||||
for (Iterator<Object> i = items.iterator(); i.hasNext(); ) {
|
||||
Object o = i.next();
|
||||
if (o instanceof ExceptionMapper)
|
||||
i.remove();
|
||||
}
|
||||
environment.jersey().register(new ApiListingResourceJSON());
|
||||
|
||||
// Swagger providers
|
||||
environment.jersey().register(new ApiDeclarationProvider());
|
||||
environment.jersey().register(new ResourceListingProvider());
|
||||
|
||||
// Swagger Scanner, which finds all the resources for @Api Annotations
|
||||
ScannerFactory.setScanner(new DefaultJaxrsScanner());
|
||||
|
||||
// Add the reader, which scans the resources and extracts the resource information
|
||||
ClassReaders.setReader(new DefaultJaxrsApiReader());
|
||||
|
||||
// Set the swagger config options
|
||||
SwaggerConfig swaggerConfig = ConfigFactory.config();
|
||||
swaggerConfig.setApiVersion("1.0.1");
|
||||
swaggerConfig.setBasePath("http://localhost:8000");
|
||||
}
|
||||
|
||||
private void removeExceptionMappers(Set<Object> items) {
|
||||
for (Iterator<Object> i = items.iterator(); i.hasNext();) {
|
||||
Object o = i.next();
|
||||
if (o instanceof ExceptionMapper)
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,185 +14,185 @@ import java.util.List;
|
|||
@ApiModel(value = "An alarm is a devops's best friend")
|
||||
@XmlRootElement(name = "Alarm")
|
||||
public class Alarm extends AbstractEntity implements Linked {
|
||||
private List<Link> links;
|
||||
private String name;
|
||||
private String description = "";
|
||||
private String expression;
|
||||
private AlarmState state;
|
||||
private boolean enabled;
|
||||
private List<String> alarmActions;
|
||||
private List<String> okActions;
|
||||
private List<String> undeterminedActions;
|
||||
private List<Link> links;
|
||||
private String name;
|
||||
private String description = "";
|
||||
private String expression;
|
||||
private AlarmState state;
|
||||
private boolean enabled;
|
||||
private List<String> alarmActions;
|
||||
private List<String> okActions;
|
||||
private List<String> undeterminedActions;
|
||||
|
||||
public Alarm() {
|
||||
}
|
||||
public Alarm() {
|
||||
}
|
||||
|
||||
public Alarm(String id, String name, String description, String expression, AlarmState state,
|
||||
boolean enabled, List<String> alarmActions, List<String> okActions,
|
||||
List<String> undeterminedActions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
setDescription(description);
|
||||
setExpression(expression);
|
||||
setState(state);
|
||||
setEnabled(enabled);
|
||||
setAlarmActions(alarmActions);
|
||||
setOkActions(okActions);
|
||||
setUndeterminedActions(undeterminedActions);
|
||||
}
|
||||
public Alarm(String id, String name, String description, String expression, AlarmState state,
|
||||
boolean enabled, List<String> alarmActions, List<String> okActions,
|
||||
List<String> undeterminedActions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
setDescription(description);
|
||||
setExpression(expression);
|
||||
setState(state);
|
||||
setEnabled(enabled);
|
||||
setAlarmActions(alarmActions);
|
||||
setOkActions(okActions);
|
||||
setUndeterminedActions(undeterminedActions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Alarm other = (Alarm) obj;
|
||||
if (alarmActions == null) {
|
||||
if (other.alarmActions != null)
|
||||
return false;
|
||||
} else if (!alarmActions.equals(other.alarmActions))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (expression == null) {
|
||||
if (other.expression != null)
|
||||
return false;
|
||||
} else if (!expression.equals(other.expression))
|
||||
return false;
|
||||
if (links == null) {
|
||||
if (other.links != null)
|
||||
return false;
|
||||
} else if (!links.equals(other.links))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (okActions == null) {
|
||||
if (other.okActions != null)
|
||||
return false;
|
||||
} else if (!okActions.equals(other.okActions))
|
||||
return false;
|
||||
if (state != other.state)
|
||||
return false;
|
||||
if (undeterminedActions == null) {
|
||||
if (other.undeterminedActions != null)
|
||||
return false;
|
||||
} else if (!undeterminedActions.equals(other.undeterminedActions))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (!super.equals(obj))
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Alarm other = (Alarm) obj;
|
||||
if (alarmActions == null) {
|
||||
if (other.alarmActions != null)
|
||||
return false;
|
||||
} else if (!alarmActions.equals(other.alarmActions))
|
||||
return false;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (expression == null) {
|
||||
if (other.expression != null)
|
||||
return false;
|
||||
} else if (!expression.equals(other.expression))
|
||||
return false;
|
||||
if (links == null) {
|
||||
if (other.links != null)
|
||||
return false;
|
||||
} else if (!links.equals(other.links))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (okActions == null) {
|
||||
if (other.okActions != null)
|
||||
return false;
|
||||
} else if (!okActions.equals(other.okActions))
|
||||
return false;
|
||||
if (state != other.state)
|
||||
return false;
|
||||
if (undeterminedActions == null) {
|
||||
if (other.undeterminedActions != null)
|
||||
return false;
|
||||
} else if (!undeterminedActions.equals(other.undeterminedActions))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<String> getAlarmActions() {
|
||||
return alarmActions;
|
||||
}
|
||||
public List<String> getAlarmActions() {
|
||||
return alarmActions;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public List<Link> getLinks() {
|
||||
return links;
|
||||
}
|
||||
public List<Link> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getOkActions() {
|
||||
return okActions;
|
||||
}
|
||||
public List<String> getOkActions() {
|
||||
return okActions;
|
||||
}
|
||||
|
||||
public AlarmState getState() {
|
||||
return state;
|
||||
}
|
||||
public AlarmState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public List<String> getUndeterminedActions() {
|
||||
return undeterminedActions;
|
||||
}
|
||||
public List<String> getUndeterminedActions() {
|
||||
return undeterminedActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((alarmActions == null) ? 0 : alarmActions.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((expression == null) ? 0 : expression.hashCode());
|
||||
result = prime * result + ((links == null) ? 0 : links.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((okActions == null) ? 0 : okActions.hashCode());
|
||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||
result = prime * result + ((undeterminedActions == null) ? 0 : undeterminedActions.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + ((alarmActions == null) ? 0 : alarmActions.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((expression == null) ? 0 : expression.hashCode());
|
||||
result = prime * result + ((links == null) ? 0 : links.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((okActions == null) ? 0 : okActions.hashCode());
|
||||
result = prime * result + ((state == null) ? 0 : state.hashCode());
|
||||
result = prime * result + ((undeterminedActions == null) ? 0 : undeterminedActions.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setAlarmActions(List<String> alarmActions) {
|
||||
this.alarmActions = alarmActions;
|
||||
}
|
||||
public void setAlarmActions(List<String> alarmActions) {
|
||||
this.alarmActions = alarmActions;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description == null ? "" : description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description == null ? "" : description;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
public void setExpression(String expression) {
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@XmlElement(name = "id")
|
||||
@ApiModelProperty(value = "Alarm ID")
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
@XmlElement(name = "id")
|
||||
@ApiModelProperty(value = "Alarm ID")
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLinks(List<Link> links) {
|
||||
this.links = links;
|
||||
}
|
||||
@Override
|
||||
public void setLinks(List<Link> links) {
|
||||
this.links = links;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setOkActions(List<String> okActions) {
|
||||
this.okActions = okActions;
|
||||
}
|
||||
public void setOkActions(List<String> okActions) {
|
||||
this.okActions = okActions;
|
||||
}
|
||||
|
||||
public void setState(AlarmState state) {
|
||||
this.state = state;
|
||||
}
|
||||
public void setState(AlarmState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public void setUndeterminedActions(List<String> undeterminedActions) {
|
||||
this.undeterminedActions = undeterminedActions;
|
||||
}
|
||||
public void setUndeterminedActions(List<String> undeterminedActions) {
|
||||
this.undeterminedActions = undeterminedActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Alarm [name=%s]", name);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Alarm [name=%s]", name);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue