Search in sources :

Example 46 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class OnmsIpInterfaceResource method updateIpInterface.

/**
     * <p>updateIpInterface</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ipAddress a {@link java.lang.String} object.
     * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{ipAddress}")
public Response updateIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final MultivaluedMapImpl params) {
    writeLock();
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        }
        final OnmsIpInterface ipInterface = node.getIpInterfaceByIpAddress(ipAddress);
        if (ipInterface == null) {
            throw getException(Status.CONFLICT, "Can't find interface with IP address {} for node {}.", ipAddress, nodeCriteria);
        }
        LOG.debug("updateIpInterface: updating ip interface {}", ipInterface);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(ipInterface);
        boolean modified = false;
        for (final String key : params.keySet()) {
            // skip nodeId since we already know the node this is associated with and don't want to overwrite it
            if ("nodeId".equals(key)) {
                continue;
            }
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateIpInterface: ip interface {} updated", ipInterface);
            m_ipInterfaceDao.saveOrUpdate(ipInterface);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 47 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class EmailNorthbounderConfigurationResource method updateEmailDestination.

/**
     * Updates a specific email destination.
     *
     * @param destinationName the destination name
     * @param params the parameters map
     * @return the response
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("destinations/{destinationName}")
public Response updateEmailDestination(@PathParam("destinationName") final String destinationName, final MultivaluedMapImpl params) {
    writeLock();
    try {
        boolean modified = false;
        final EmailDestination destination = getEmailDestination(destinationName);
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(destination);
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            saveConfiguration();
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) EmailDestination(org.opennms.netmgt.alarmd.northbounder.email.EmailDestination) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 48 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class OnmsMonitoredServiceResource method updateService.

/**
     * <p>updateService</p>
     *
     * @param nodeCriteria a {@link java.lang.String} object.
     * @param ipAddress a {@link java.lang.String} object.
     * @param serviceName a {@link java.lang.String} object.
     * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null)
            throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null)
            throw getException(Status.BAD_REQUEST, "IP Interface {} was not found on node {}.", ipAddress, nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null)
            throw getException(Status.BAD_REQUEST, "Monitored Service {} was not found on IP Interface {} and node {}.", serviceName, ipAddress, nodeCriteria);
        LOG.debug("updateService: updating service {}", service);
        boolean modified = false;
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
        for (String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                if (key.equals("status")) {
                    if ("S".equals(value) || ("A".equals(service.getStatus()) && "F".equals(value))) {
                        LOG.debug("updateService: suspending polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "F";
                        sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
                    }
                    if ("R".equals(value) || ("F".equals(service.getStatus()) && "A".equals(value))) {
                        LOG.debug("updateService: resuming polling for service {} on node with IP {}", service.getServiceName(), service.getIpAddress().getHostAddress());
                        value = "A";
                        sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
                    }
                }
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateSservice: service {} updated", service);
            m_serviceDao.saveOrUpdate(service);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 49 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class SnmpConfigRestService method setSnmpInfo.

/**
     * <p>setSnmpInfo</p>
     *
     * @param ipAddress a {@link java.lang.String} object.
     * @param snmpInfo a {@link org.opennms.web.snmpinfo.SnmpInfo} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Path("{ipAddr}")
public Response setSnmpInfo(@PathParam("ipAddr") final String ipAddress, final SnmpInfo snmpInfo) {
    writeLock();
    try {
        final SnmpEventInfo eventInfo;
        if (ipAddress.contains("-")) {
            final String[] addrs = SnmpConfigRestService.getAddresses(ipAddress);
            eventInfo = snmpInfo.createEventInfo(addrs[0], addrs[1]);
        } else {
            eventInfo = snmpInfo.createEventInfo(ipAddress);
        }
        m_accessService.define(eventInfo);
        return Response.noContent().build();
    } catch (final Throwable e) {
        throw getException(Status.INTERNAL_SERVER_ERROR, "Can't update SNMP configuration for {} : {}", ipAddress, e.getMessage());
    } finally {
        writeUnlock();
    }
}
Also used : SnmpEventInfo(org.opennms.netmgt.config.SnmpEventInfo) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 50 with PUT

use of javax.ws.rs.PUT in project opennms by OpenNMS.

the class AlarmRestService method updateAlarms.

/**
     * <p>
     * updateAlarms
     * </p>
     * 
     * @param formProperties
     *            a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     */
@PUT
@Transactional
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateAlarms(@Context final SecurityContext securityContext, final MultivaluedMapImpl formProperties) {
    writeLock();
    try {
        final String ackValue = formProperties.getFirst("ack");
        formProperties.remove("ack");
        final String escalateValue = formProperties.getFirst("escalate");
        formProperties.remove("escalate");
        final String clearValue = formProperties.getFirst("clear");
        formProperties.remove("clear");
        final CriteriaBuilder builder = getCriteriaBuilder(formProperties, false);
        builder.distinct();
        builder.limit(0);
        builder.offset(0);
        final String ackUser = formProperties.containsKey("ackUser") ? formProperties.getFirst("ackUser") : securityContext.getUserPrincipal().getName();
        formProperties.remove("ackUser");
        assertUserEditCredentials(securityContext, ackUser);
        final List<OnmsAlarm> alarms = m_alarmDao.findMatching(builder.toCriteria());
        for (final OnmsAlarm alarm : alarms) {
            final OnmsAcknowledgment acknowledgement = new OnmsAcknowledgment(alarm, ackUser);
            acknowledgement.setAckAction(AckAction.UNSPECIFIED);
            if (ackValue != null) {
                if (Boolean.parseBoolean(ackValue)) {
                    acknowledgement.setAckAction(AckAction.ACKNOWLEDGE);
                } else {
                    acknowledgement.setAckAction(AckAction.UNACKNOWLEDGE);
                }
            } else if (escalateValue != null) {
                if (Boolean.parseBoolean(escalateValue)) {
                    acknowledgement.setAckAction(AckAction.ESCALATE);
                }
            } else if (clearValue != null) {
                if (Boolean.parseBoolean(clearValue)) {
                    acknowledgement.setAckAction(AckAction.CLEAR);
                }
            } else {
                throw getException(Status.BAD_REQUEST, "Must supply one of the 'ack', 'escalate', or 'clear' parameters, set to either 'true' or 'false'.");
            }
            m_ackDao.processAck(acknowledgement);
        }
        return alarms == null || alarms.isEmpty() ? Response.notModified().build() : Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11