Search in sources :

Example 26 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class CacheBolt method emitRerouteCommands.

private void emitRerouteCommands(Set<ImmutablePair<Flow, Flow>> flows, Tuple tuple, String correlationId, FlowOperation operation) {
    for (ImmutablePair<Flow, Flow> flow : flows) {
        try {
            flow.getLeft().setState(FlowState.DOWN);
            flow.getRight().setState(FlowState.DOWN);
            FlowRerouteRequest request = new FlowRerouteRequest(flow.getLeft(), operation);
            Values values = new Values(Utils.MAPPER.writeValueAsString(new CommandMessage(request, System.currentTimeMillis(), correlationId, Destination.WFM)));
            outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, values);
            logger.debug("Flow {} reroute command message sent with correlationId {}", flow.getLeft().getFlowId(), correlationId);
        } catch (JsonProcessingException exception) {
            logger.error("Could not format flow reroute request by flow={}", flow, exception);
        }
    }
}
Also used : Values(org.apache.storm.tuple.Values) FlowRerouteRequest(org.openkilda.messaging.command.flow.FlowRerouteRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 27 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class CacheBolt method emitRestoreCommands.

private void emitRestoreCommands(Set<ImmutablePair<Flow, Flow>> flows, Tuple tuple) {
    if (flows != null) {
        ResourceCache resourceCache = new ResourceCache();
        for (ImmutablePair<Flow, Flow> flow : flows) {
            resourceCache.allocateFlow(flow);
        }
        for (ImmutablePair<Flow, Flow> flow : flows) {
            try {
                FlowRestoreRequest request = new FlowRestoreRequest(flowCache.buildFlow(flow.getLeft(), new ImmutablePair<>(null, null), resourceCache));
                resourceCache.deallocateFlow(flow);
                Values values = new Values(Utils.MAPPER.writeValueAsString(new CommandMessage(request, System.currentTimeMillis(), UUID.randomUUID().toString(), Destination.WFM)));
                outputCollector.emit(StreamType.WFM_DUMP.toString(), tuple, values);
                logger.info("Flow {} restore command message sent", flow.getLeft().getFlowId());
            } catch (JsonProcessingException exception) {
                logger.error("Could not format flow restore request by flow={}", flow, exception);
            }
        }
    }
}
Also used : ImmutablePair(org.openkilda.messaging.model.ImmutablePair) Values(org.apache.storm.tuple.Values) FlowRestoreRequest(org.openkilda.messaging.command.flow.FlowRestoreRequest) ResourceCache(org.openkilda.pce.cache.ResourceCache) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Flow(org.openkilda.messaging.model.Flow) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 28 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class OFELinkBolt method sendNetworkRequest.

/**
 * Send network dump request to FL
 */
private void sendNetworkRequest(Tuple tuple) {
    try {
        logger.debug("Send network dump request");
        CommandMessage command = new CommandMessage(new NetworkCommandData(), System.currentTimeMillis(), Utils.SYSTEM_CORRELATION_ID, Destination.CONTROLLER);
        String json = Utils.MAPPER.writeValueAsString(command);
        collector.emit(islDiscoveryTopic, tuple, new Values(PAYLOAD, json));
    } catch (JsonProcessingException exception) {
        logger.error("Could not serialize network cache request", exception);
    }
}
Also used : Values(org.apache.storm.tuple.Values) NetworkCommandData(org.openkilda.messaging.command.discovery.NetworkCommandData) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CommandMessage(org.openkilda.messaging.command.CommandMessage)

Example 29 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class NorthboundReplyBolt method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(Tuple tuple) {
    ComponentType componentId = ComponentType.valueOf(tuple.getSourceComponent());
    StreamType streamId = StreamType.valueOf(tuple.getSourceStreamId());
    Message message = (Message) tuple.getValueByField(AbstractTopology.MESSAGE_FIELD);
    Values values = null;
    try {
        logger.debug("Request tuple={}", tuple);
        switch(componentId) {
            case TOPOLOGY_ENGINE_BOLT:
            case CRUD_BOLT:
            case ERROR_BOLT:
                logger.debug("Flow response: {}={}, component={}, stream={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), componentId, streamId, message);
                message.setDestination(Destination.NORTHBOUND);
                values = new Values(MAPPER.writeValueAsString(message));
                outputCollector.emit(StreamType.RESPONSE.toString(), tuple, values);
                break;
            default:
                logger.debug("Flow unknown response: {}={}, component={}, stream={}, message={}", Utils.CORRELATION_ID, message.getCorrelationId(), componentId, streamId, message);
                break;
        }
    } catch (JsonProcessingException exception) {
        logger.error("Could not serialize message: component={}, stream={}, message={}", componentId, streamId, message);
    } finally {
        logger.debug("Northbound-Reply message ack: component={}, stream={}, tuple={}, values={}", tuple.getSourceComponent(), tuple.getSourceStreamId(), tuple, values);
        outputCollector.ack(tuple);
    }
}
Also used : StreamType(org.openkilda.wfm.topology.flow.StreamType) ComponentType(org.openkilda.wfm.topology.flow.ComponentType) Message(org.openkilda.messaging.Message) Values(org.apache.storm.tuple.Values) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 30 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project open-kilda by telstra.

the class ControllerUtils method addStaticFlow.

public void addStaticFlow(StaticFlowEntry flow) throws JsonProcessingException, FloodlightQueryException {
    Response response;
    String json = Utils.MAPPER.writeValueAsString(flow);
    try {
        response = restClient.target(DefaultParameters.FLOODLIGHT_ENDPOINT).path("/wm/staticentrypusher/json").request().accept(MediaType.APPLICATION_JSON).post(Entity.json(json));
    } catch (ProcessingException e) {
        throw new FloodlightQueryException(e);
    }
    if (response.getStatus() != 200) {
        throw new FloodlightQueryException(201, response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)648 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)205 IOException (java.io.IOException)156 HashMap (java.util.HashMap)105 Map (java.util.Map)77 ArrayList (java.util.ArrayList)67 JsonNode (com.fasterxml.jackson.databind.JsonNode)54 List (java.util.List)50 Test (org.junit.Test)44 InputStream (java.io.InputStream)24 Collectors (java.util.stream.Collectors)24 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)23 Json (com.sequenceiq.cloudbreak.domain.json.Json)21 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 Function (java.util.function.Function)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Date (java.util.Date)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)15 URL (java.net.URL)15