Search in sources :

Example 1 with IbisAction

use of nl.nn.adapterframework.configuration.IbisManager.IbisAction in project iaf by ibissource.

the class IbisActionJob method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    // Try and parse the JobDefFunction as an IbisAction
    this.ibisAction = EnumUtils.parse(IbisAction.class, "function", jobAction.name());
    if (StringUtils.isEmpty(getAdapterName())) {
        throw new ConfigurationException("a adapterName must be specified");
    }
    Adapter adapter = adapterManager.getAdapter(getAdapterName());
    if (adapter == null) {
        // Make sure the adapter is registered in this configuration
        String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] not registered.";
        throw new ConfigurationException(msg);
    }
    if (jobAction == Action.STOPRECEIVER || jobAction == Action.STARTRECEIVER) {
        if (StringUtils.isEmpty(getReceiverName())) {
            throw new ConfigurationException("a receiverName must be specified");
        }
        if (adapter.getReceiverByName(getReceiverName()) == null) {
            String msg = "Jobdef [" + getName() + "] got error: adapter [" + getAdapterName() + "] receiver [" + getReceiverName() + "] not registered.";
            throw new ConfigurationException(msg);
        }
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) IbisAction(nl.nn.adapterframework.configuration.IbisManager.IbisAction) Adapter(nl.nn.adapterframework.core.Adapter)

Example 2 with IbisAction

use of nl.nn.adapterframework.configuration.IbisManager.IbisAction in project iaf by ibissource.

the class ShowConfigurationStatus method updateAdapters.

@SuppressWarnings("unchecked")
// Normally you don't use the PUT method on a collection...
@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateAdapters(LinkedHashMap<String, Object> json) throws ApiException {
    // PUT defaults to no content
    Response.ResponseBuilder response = Response.status(Response.Status.NO_CONTENT);
    IbisAction action = null;
    ArrayList<String> adapters = new ArrayList<>();
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equalsIgnoreCase("action")) {
            // Start or stop an adapter!
            if (value.equals("stop")) {
                action = IbisAction.STOPADAPTER;
            }
            if (value.equals("start")) {
                action = IbisAction.STARTADAPTER;
            }
        }
        if (key.equalsIgnoreCase("adapters")) {
            try {
                adapters.addAll((ArrayList<String>) value);
            } catch (Exception e) {
                return response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
            }
        }
    }
    if (action != null) {
        response.status(Response.Status.ACCEPTED);
        if (adapters.isEmpty()) {
            getIbisManager().handleAction(action, "*ALL*", "*ALL*", null, getUserPrincipalName(), false);
        } else {
            for (Iterator<String> iterator = adapters.iterator(); iterator.hasNext(); ) {
                String adapterName = iterator.next();
                getIbisManager().handleAction(action, "", adapterName, null, getUserPrincipalName(), false);
            }
        }
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ArrayList(java.util.ArrayList) IbisAction(nl.nn.adapterframework.configuration.IbisManager.IbisAction) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) ListenerException(nl.nn.adapterframework.core.ListenerException) IOException(java.io.IOException) 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)

Example 3 with IbisAction

use of nl.nn.adapterframework.configuration.IbisManager.IbisAction in project iaf by ibissource.

the class ShowConfigurationStatus method updateReceiver.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}/receivers/{receiverName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateReceiver(@PathParam("adapterName") String adapterName, @PathParam("receiverName") String receiverName, LinkedHashMap<String, Object> json) throws ApiException {
    Adapter adapter = getAdapter(adapterName);
    Receiver<?> receiver = adapter.getReceiverByName(receiverName);
    if (receiver == null) {
        throw new ApiException("Receiver [" + receiverName + "] not found!");
    }
    // PUT defaults to no content
    Response.ResponseBuilder response = Response.status(Response.Status.NO_CONTENT);
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equalsIgnoreCase("action")) {
            // Start or stop an adapter!
            IbisAction action = null;
            if (value.equals("stop")) {
                action = IbisAction.STOPRECEIVER;
            } else if (value.equals("start")) {
                action = IbisAction.STARTRECEIVER;
            } else if (value.equals("incthread")) {
                action = IbisAction.INCTHREADS;
            } else if (value.equals("decthread")) {
                action = IbisAction.DECTHREADS;
            }
            if (action == null)
                throw new ApiException("no or unknown action provided");
            getIbisManager().handleAction(action, "", adapterName, receiverName, getUserPrincipalName(), false);
            response.entity("{\"status\":\"ok\"}");
        }
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IbisAction(nl.nn.adapterframework.configuration.IbisManager.IbisAction) Adapter(nl.nn.adapterframework.core.Adapter) 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)

Example 4 with IbisAction

use of nl.nn.adapterframework.configuration.IbisManager.IbisAction in project iaf by ibissource.

the class ShowConfigurationStatus method updateAdapter.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/adapters/{adapterName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateAdapter(@PathParam("adapterName") String adapterName, LinkedHashMap<String, Object> json) throws ApiException {
    // Check if the adapter exists!
    getAdapter(adapterName);
    // PUT defaults to no content
    Response.ResponseBuilder response = Response.status(Response.Status.NO_CONTENT);
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equalsIgnoreCase("action")) {
            // Start or stop an adapter!
            IbisAction action = null;
            if (value.equals("stop")) {
                action = IbisAction.STOPADAPTER;
            }
            if (value.equals("start")) {
                action = IbisAction.STARTADAPTER;
            }
            getIbisManager().handleAction(action, "", adapterName, null, getUserPrincipalName(), false);
            response.entity("{\"status\":\"ok\"}");
        }
    }
    return response.build();
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) IbisAction(nl.nn.adapterframework.configuration.IbisManager.IbisAction) 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

IbisAction (nl.nn.adapterframework.configuration.IbisManager.IbisAction)4 RolesAllowed (javax.annotation.security.RolesAllowed)3 Consumes (javax.ws.rs.Consumes)3 PUT (javax.ws.rs.PUT)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)3 Adapter (nl.nn.adapterframework.core.Adapter)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 SAXException (org.xml.sax.SAXException)1