use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class FlowsResource method getFlows.
/**
* The method returns the flow for the switch from the request.
*/
@Get("json")
@SuppressWarnings("unchecked")
public Map<String, Object> getFlows() throws SwitchOperationException {
Map<String, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
LOGGER.debug("Get flows for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
List<OFFlowStatsEntry> flowEntries = switchManager.dumpFlowTable(DatapathId.of(switchId));
LOGGER.debug("OF_STATS: {}", flowEntries);
if (flowEntries != null) {
for (OFFlowStatsEntry entry : flowEntries) {
String key = String.format("flow-0x%s", Long.toHexString(entry.getCookie().getValue()).toUpperCase());
response.put(key, buildFlowStat(entry));
}
}
} catch (IllegalArgumentException exception) {
String messageString = "No such switch";
LOGGER.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
}
return response;
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class MetersResource method getMeters.
// FIXME(surabujin): is it used anywhere?
/**
* Gets meters.
* @return the map of meters.
*/
@Get("json")
@SuppressWarnings("unchecked")
public Map<Long, Object> getMeters() {
Map<Long, Object> response = new HashMap<>();
String switchId = (String) this.getRequestAttributes().get("switch_id");
logger.debug("Get meters for switch: {}", switchId);
ISwitchManager switchManager = (ISwitchManager) getContext().getAttributes().get(ISwitchManager.class.getCanonicalName());
try {
List<OFMeterConfig> meters = switchManager.dumpMeters(DatapathId.of(switchId));
if (meters != null) {
logger.debug("Meters from switch {} received: {}", switchId, meters.size());
for (OFMeterConfig entry : meters) {
response.put(entry.getMeterId(), entry);
}
}
} catch (UnsupportedSwitchOperationException ex) {
String messageString = "Not supported";
logger.error("{}: {}", messageString, switchId, ex);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, ex.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.SERVER_ERROR_NOT_IMPLEMENTED);
} catch (IllegalArgumentException | SwitchOperationException exception) {
String messageString = "No such switch";
logger.error("{}: {}", messageString, switchId, exception);
MessageError responseMessage = new MessageError(CorrelationContext.getId(), System.currentTimeMillis(), ErrorType.PARAMETERS_INVALID.toString(), messageString, exception.getMessage());
response.putAll(MAPPER.convertValue(responseMessage, Map.class));
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
}
return response;
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class FlowControllerTest method emptyCredentials.
@Test
public void emptyCredentials() throws Exception {
MvcResult result = mockMvc.perform(get("/v1/flows/path/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, DEFAULT_CORRELATION_ID).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isUnauthorized()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
MessageError response = MAPPER.readValue(result.getResponse().getContentAsString(), MessageError.class);
assertEquals(AUTH_ERROR, response);
}
use of org.openkilda.messaging.error.MessageError in project open-kilda by telstra.
the class GrpcBasicAuthenticationEntryPoint method commence.
/**
* {@inheritDoc}
*/
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
String realm = String.format("Basic realm=%s", getRealmName());
response.addHeader(HttpHeaders.WWW_AUTHENTICATE, realm);
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
String correlationId = Optional.ofNullable(request.getHeader(CORRELATION_ID)).orElse(DEFAULT_CORRELATION_ID);
MessageError error = new MessageError(correlationId, System.currentTimeMillis(), ErrorType.AUTH_FAILED.toString(), DEFAULT_REALM, exception.getClass().getSimpleName());
response.getWriter().print(MAPPER.writeValueAsString(error));
}
Aggregations