Search in sources :

Example 76 with RolesAllowed

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();
}
Also used : Scheduler(org.quartz.Scheduler) Date(java.util.Date) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) SchedulerException(org.quartz.SchedulerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 77 with RolesAllowed

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();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Scheduler(org.quartz.Scheduler) SenderException(nl.nn.adapterframework.core.SenderException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) SchedulerException(org.quartz.SchedulerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 78 with RolesAllowed

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();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) SenderException(nl.nn.adapterframework.core.SenderException) HashMap(java.util.HashMap) Map(java.util.Map) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 79 with RolesAllowed

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();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Adapter(nl.nn.adapterframework.core.Adapter) EntityTag(javax.ws.rs.core.EntityTag) TreeMap(java.util.TreeMap) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 80 with RolesAllowed

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();
}
Also used : Configuration(nl.nn.adapterframework.configuration.Configuration) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

RolesAllowed (javax.annotation.security.RolesAllowed)191 Path (javax.ws.rs.Path)127 Produces (javax.ws.rs.Produces)110 Consumes (javax.ws.rs.Consumes)55 GET (javax.ws.rs.GET)54 POST (javax.ws.rs.POST)40 PUT (javax.ws.rs.PUT)35 HashMap (java.util.HashMap)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)30 ApiOperation (io.swagger.annotations.ApiOperation)29 ApiResponses (io.swagger.annotations.ApiResponses)29 Response (javax.ws.rs.core.Response)28 Adapter (nl.nn.adapterframework.core.Adapter)21 DELETE (javax.ws.rs.DELETE)19 WebApplicationException (org.rembx.jeeshop.rest.WebApplicationException)19 LinkedHashMap (java.util.LinkedHashMap)16 Locale (java.util.Locale)16 Map (java.util.Map)12 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)12