use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowScheduler method updateScheduler.
@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules/")
@Relation("schedules")
@Produces(MediaType.APPLICATION_JSON)
public Response updateScheduler(LinkedHashMap<String, Object> json) throws ApiException {
Scheduler scheduler = getScheduler();
String action = null;
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
if (key.equalsIgnoreCase("action")) {
action = entry.getValue().toString();
}
}
try {
String commandIssuedBy = servletConfig.getInitParameter("remoteHost");
commandIssuedBy += servletConfig.getInitParameter("remoteAddress");
commandIssuedBy += servletConfig.getInitParameter("remoteUser");
if (action.equalsIgnoreCase("start")) {
if (scheduler.isInStandbyMode() || scheduler.isShutdown()) {
scheduler.start();
log.info("start scheduler:" + new Date() + commandIssuedBy);
} else {
throw new ApiException("Failed to start scheduler");
}
} else if (action.equalsIgnoreCase("pause")) {
if (scheduler.isStarted()) {
scheduler.standby();
log.info("pause scheduler:" + new Date() + commandIssuedBy);
} else {
throw new ApiException("Failed to pause scheduler");
}
} else if (action.equalsIgnoreCase("stop")) {
if (scheduler.isStarted() || scheduler.isInStandbyMode()) {
scheduler.shutdown();
log.info("shutdown scheduler:" + new Date() + commandIssuedBy);
} else {
throw new ApiException("Failed to stop scheduler");
}
} else {
return Response.status(Response.Status.BAD_REQUEST).build();
}
} catch (Exception e) {
log.error("unable to run action [" + action + "]", e);
}
return Response.status(Response.Status.OK).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowScheduler method getSchedules.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules")
@Relation("schedules")
@Produces(MediaType.APPLICATION_JSON)
public Response getSchedules() throws ApiException {
Scheduler scheduler = getScheduler();
Map<String, Object> returnMap = new HashMap<String, Object>();
try {
returnMap.put("scheduler", getSchedulerMetaData(scheduler));
returnMap.put("jobs", getJobGroupNamesWithJobs(scheduler));
} catch (Exception e) {
throw new ApiException("Failed to parse destinations", e);
}
return Response.status(Response.Status.OK).entity(returnMap).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowAdapterStatistics method getStatistics.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/statistics")
@Relation("statistics")
@Produces(MediaType.APPLICATION_JSON)
public Response getStatistics(@PathParam("adapterName") String adapterName) throws ApiException {
Map<String, Object> statisticsMap = new HashMap<String, Object>();
statisticsMap.put("labels", StatisticsKeeper.getLabels());
statisticsMap.put("types", StatisticsKeeper.getTypes());
Adapter adapter = getIbisManager().getRegisteredAdapter(adapterName);
if (adapter == null) {
throw new ApiException("Adapter not found!");
}
StatisticsKeeper sk = adapter.getStatsMessageProcessingDuration();
statisticsMap.put("totalMessageProccessingTime", sk.asMap());
long[] numOfMessagesStartProcessingByHour = adapter.getNumOfMessagesStartProcessingByHour();
List<Map<String, Object>> hourslyStatistics = new ArrayList<Map<String, Object>>();
for (int i = 0; i < numOfMessagesStartProcessingByHour.length; i++) {
Map<String, Object> item = new HashMap<String, Object>(2);
String startTime;
if (i < 10) {
startTime = "0" + i + ":00";
} else {
startTime = i + ":00";
}
item.put("time", startTime);
item.put("count", numOfMessagesStartProcessingByHour[i]);
hourslyStatistics.add(item);
}
statisticsMap.put("hourly", hourslyStatistics);
List<Map<String, Object>> receivers = new ArrayList<Map<String, Object>>();
for (Receiver<?> receiver : adapter.getReceivers()) {
Map<String, Object> receiverMap = new HashMap<String, Object>();
receiverMap.put("name", receiver.getName());
receiverMap.put("class", receiver.getClass().getName());
receiverMap.put("messagesReceived", receiver.getMessagesReceived());
receiverMap.put("messagesRetried", receiver.getMessagesRetried());
ArrayList<Map<String, Object>> procStatsMap = new ArrayList<Map<String, Object>>();
// procStatsXML.addSubElement(statisticsKeeperToXmlBuilder(statReceiver.getResponseSizeStatistics(), "stat"));
for (StatisticsKeeper pstat : receiver.getProcessStatistics()) {
procStatsMap.add(pstat.asMap());
}
receiverMap.put("processing", procStatsMap);
ArrayList<Map<String, Object>> idleStatsMap = new ArrayList<Map<String, Object>>();
for (StatisticsKeeper istat : receiver.getIdleStatistics()) {
idleStatsMap.add(istat.asMap());
}
receiverMap.put("idle", idleStatsMap);
receivers.add(receiverMap);
}
statisticsMap.put("receivers", receivers);
Map<String, Object> tmp = new HashMap<String, Object>();
StatisticsKeeperToMap handler = new StatisticsKeeperToMap(tmp);
handler.configure();
Object handle = handler.start(null, null, null);
try {
adapter.getPipeLine().iterateOverStatistics(handler, tmp, Action.FULL);
statisticsMap.put("durationPerPipe", tmp.get("pipeStats"));
statisticsMap.put("sizePerPipe", tmp.get("sizeStats"));
} catch (SenderException e) {
log.error("unable to parse pipeline statistics", e);
} finally {
handler.end(handle);
}
return Response.status(Response.Status.CREATED).entity(statisticsMap).build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowConfigurationStatus method getAdapters.
@GET
@RolesAllowed({ "IbisObserver", "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters")
@Produces(MediaType.APPLICATION_JSON)
public Response getAdapters(@QueryParam("expanded") String expanded, @QueryParam("showPendingMsgCount") boolean showPendingMsgCount) throws ApiException {
TreeMap<String, Object> adapterList = new TreeMap<String, Object>();
for (Adapter adapter : getIbisManager().getRegisteredAdapters()) {
Map<String, Object> adapterInfo = mapAdapter(adapter);
if (expanded != null && !expanded.isEmpty()) {
if (expanded.equalsIgnoreCase("all")) {
adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
adapterInfo.put("pipes", mapAdapterPipes(adapter));
adapterInfo.put("messages", mapAdapterMessages(adapter));
} else if (expanded.equalsIgnoreCase("receivers")) {
adapterInfo.put("receivers", mapAdapterReceivers(adapter, showPendingMsgCount));
} else if (expanded.equalsIgnoreCase("pipes")) {
adapterInfo.put("pipes", mapAdapterPipes(adapter));
} else if (expanded.equalsIgnoreCase("messages")) {
adapterInfo.put("messages", mapAdapterMessages(adapter));
} else {
throw new ApiException("Invalid value [" + expanded + "] for parameter expanded supplied!");
}
}
adapterList.put((String) adapterInfo.get("name"), adapterInfo);
}
Response.ResponseBuilder response = null;
// Calculate the ETag on last modified date of user resource
EntityTag etag = new EntityTag(adapterList.hashCode() + "");
// Verify if it matched with etag available in http request
response = request.evaluatePreconditions(etag);
// If ETag matches the response will be non-null;
if (response != null) {
return response.tag(etag).build();
}
response = Response.status(Response.Status.OK).entity(adapterList).tag(etag);
return response.build();
}
use of javax.annotation.security.RolesAllowed in project iaf by ibissource.
the class ShowConfiguration method manageConfiguration.
@PUT
@RolesAllowed({ "IbisTester", "IbisAdmin", "IbisDataAdmin" })
@Path("/configurations/{configuration}/versions/{version}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response manageConfiguration(@PathParam("configuration") String configurationName, @PathParam("version") String encodedVersion, @QueryParam("realm") String jmsRealm, LinkedHashMap<String, Object> json) throws ApiException {
Configuration configuration = getIbisManager().getConfiguration(configurationName);
if (configuration == null) {
throw new ApiException("Configuration not found!");
}
String version = Misc.urlDecode(encodedVersion);
try {
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
Object valueObject = entry.getValue();
boolean value = false;
if (valueObject instanceof Boolean) {
value = (boolean) valueObject;
} else
value = Boolean.parseBoolean(valueObject.toString());
if (key.equalsIgnoreCase("activate")) {
if (ConfigurationUtils.activateConfig(getIbisContext(), configurationName, version, value, jmsRealm)) {
return Response.status(Response.Status.ACCEPTED).build();
}
} else if (key.equalsIgnoreCase("autoreload")) {
if (ConfigurationUtils.autoReloadConfig(getIbisContext(), configurationName, version, value, jmsRealm)) {
return Response.status(Response.Status.ACCEPTED).build();
}
}
}
} catch (Exception e) {
throw new ApiException(e);
}
return Response.status(Response.Status.BAD_REQUEST).build();
}
Aggregations