Skip to content

Commit

Permalink
Improvements for
Browse files Browse the repository at this point in the history
- Sorting
- Websockets (flow management)
- Importing
  • Loading branch information
assimbly committed Jan 4, 2019
1 parent 09ab870 commit a16fd71
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 118 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ dependencies {
compile "org.jdom:jdom2:2.0.6"
compile "org.springframework:spring-websocket:5.0.7.RELEASE"
compile "org.springframework.security:spring-security-messaging:5.0.7.RELEASE"
// compile "io.hawt:hawtio-springboot:2.4.0"
compile "io.hawt:hawtio-springboot:2.4.0"

// end custom dependencies

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/assimbly/gateway/event/FailureListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

// This class listens to failure events in camel exchanges (routes) and send them to the websocket topic: topic/alert
// Check the following page for all EventObject instances of Camel: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/management/event/package-summary.html
Expand All @@ -22,27 +21,29 @@ public class FailureListener extends EventNotifierSupport {

@Autowired
private SimpMessageSendingOperations messagingTemplate;

private String flowId;

public void notify(EventObject eventObject) throws Exception {

if (eventObject instanceof ExchangeFailureHandledEvent) {

ExchangeFailureHandledEvent exchangeFailedEvent = (ExchangeFailureHandledEvent) eventObject;
String flowId = exchangeFailedEvent.getExchange().getFromRouteId();
flowId = exchangeFailedEvent.getExchange().getFromRouteId();

if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/alert", flowId);
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/alert","alert:" + flowId);
}else {
log.warn("Can't send alert to websocket. messagingTemplate=null");
}

}if (eventObject instanceof ExchangeFailedEvent) {
}else if (eventObject instanceof ExchangeFailedEvent) {

ExchangeFailedEvent exchangeFailedEvent = (ExchangeFailedEvent) eventObject;
String flowId = exchangeFailedEvent.getExchange().getFromRouteId();
flowId = exchangeFailedEvent.getExchange().getFromRouteId();

if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/alert", flowId);
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/alert","alert:" + flowId);
}else {
log.warn("Can't send alert to websocket. messagingTemplate=null");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.assimbly.gateway.service;

import org.assimbly.gateway.service.dto.EnvironmentVariablesDTO;
import org.assimbly.gateway.service.dto.FlowDTO;
import org.assimbly.gateway.service.dto.HeaderDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;
Expand All @@ -23,8 +27,7 @@ public interface EnvironmentVariablesService {
*
* @return the list of entities
*/
List<EnvironmentVariablesDTO> findAll();

Page<EnvironmentVariablesDTO> findAll(Pageable pageable);

/**
* Get the "id" environmentVariables.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.assimbly.gateway.service;

import org.assimbly.gateway.service.dto.FlowDTO;
import org.assimbly.gateway.service.dto.HeaderDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;
Expand All @@ -23,7 +26,8 @@ public interface HeaderService {
*
* @return the list of entities
*/
List<HeaderDTO> findAll();
Page<HeaderDTO> findAll(Pageable pageable);



/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.assimbly.gateway.service;

import org.assimbly.gateway.service.dto.FlowDTO;
import org.assimbly.gateway.service.dto.ServiceDTO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;
Expand All @@ -23,7 +26,7 @@ public interface ServiceService {
*
* @return the list of entities
*/
List<ServiceDTO> findAll();
Page<ServiceDTO> findAll(Pageable pageable);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import org.assimbly.gateway.service.mapper.EnvironmentVariablesMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* Service Implementation for managing EnvironmentVariables.
Expand Down Expand Up @@ -54,16 +52,16 @@ public EnvironmentVariablesDTO save(EnvironmentVariablesDTO environmentVariables
*
* @return the list of entities
*/

@Override
@Transactional(readOnly = true)
public List<EnvironmentVariablesDTO> findAll() {
log.debug("Request to get all EnvironmentVariables");
return environmentVariablesRepository.findAll().stream()
.map(environmentVariablesMapper::toDto)
.collect(Collectors.toCollection(LinkedList::new));
public Page<EnvironmentVariablesDTO> findAll(Pageable pageable) {
log.debug("Request to get all Environment variables");
return environmentVariablesRepository.findAll(pageable)
.map(environmentVariablesMapper::toDto);
}


/**
* Get one environmentVariables by id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import org.assimbly.gateway.service.HeaderService;
import org.assimbly.gateway.domain.Header;
import org.assimbly.gateway.repository.HeaderRepository;
import org.assimbly.gateway.service.dto.EnvironmentVariablesDTO;
import org.assimbly.gateway.service.dto.HeaderDTO;
import org.assimbly.gateway.service.mapper.HeaderMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -48,22 +50,15 @@ public HeaderDTO save(HeaderDTO headerDTO) {
header = headerRepository.save(header);
return headerMapper.toDto(header);
}

/**
* Get all the headers.
*
* @return the list of entities
*/

@Override
@Transactional(readOnly = true)
public List<HeaderDTO> findAll() {
public Page<HeaderDTO> findAll(Pageable pageable) {
log.debug("Request to get all Headers");
return headerRepository.findAll().stream()
.map(headerMapper::toDto)
.collect(Collectors.toCollection(LinkedList::new));
return headerRepository.findAll(pageable)
.map(headerMapper::toDto);
}


/**
* Get one header by id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.assimbly.gateway.service.ServiceService;
import org.assimbly.gateway.repository.ServiceRepository;
import org.assimbly.gateway.service.dto.HeaderDTO;
import org.assimbly.gateway.service.dto.ServiceDTO;
import org.assimbly.gateway.service.mapper.ServiceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -47,22 +49,15 @@ public ServiceDTO save(ServiceDTO serviceDTO) {
service = serviceRepository.save(service);
return serviceMapper.toDto(service);
}

/**
* Get all the services.
*
* @return the list of entities
*/

@Override
@Transactional(readOnly = true)
public List<ServiceDTO> findAll() {
log.debug("Request to get all Services");
return serviceRepository.findAll().stream()
.map(serviceMapper::toDto)
.collect(Collectors.toCollection(LinkedList::new));
public Page<ServiceDTO> findAll(Pageable pageable) {
log.debug("Request to get all Headers");
return serviceRepository.findAll(pageable)
.map(serviceMapper::toDto);
}


/**
* Get one service by id.
*
Expand Down
47 changes: 42 additions & 5 deletions src/main/java/org/assimbly/gateway/web/rest/ConnectorResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.assimbly.gateway.web.rest.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.NativeWebRequest;

Expand Down Expand Up @@ -44,7 +45,10 @@ public class ConnectorResource {

@Autowired
FailureListener failureListener;


@Autowired
private SimpMessageSendingOperations messagingTemplate;

public ConnectorResource() {}

//configure connector (by gatewayid)
Expand Down Expand Up @@ -224,16 +228,30 @@ public ResponseEntity<String> setMaintenance(@ApiParam(hidden = true) @RequestHe

try {

//pass spring variable into new Thread (outside of Spring context)
final SimpMessageSendingOperations messagingTemplate2 = messagingTemplate;

Thread thread = new Thread(new Runnable()
{
public void run()
{

SimpMessageSendingOperations messagingTemplate = messagingTemplate2;

public void run()
{

try {
for(Long id : ids) {
flowId = id.toString();
status = connector.getFlowStatus(flowId);
if(status.equals("started")) {
connector.pauseFlow(flowId);
status = connector.pauseFlow(flowId);
if(status.equals("suspended") || status.equals("stopped")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:suspended");
}
}else {
throw new Exception(status);
}
}
}

Expand All @@ -244,7 +262,11 @@ public void run()
flowId = id.toString();
status = connector.getFlowStatus(flowId);
if(status.equals("suspended")) {
connector.resumeFlow(flowId);
if(status.equals("started")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:resumed");
}
}
}
}

Expand Down Expand Up @@ -340,6 +362,9 @@ public ResponseEntity<String> startflow(@ApiParam(hidden = true) @RequestHeader(
flowId = id.toString();
status = connector.startFlow(flowId);
if(status.equals("started")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:started");
}
return ResponseUtil.createSuccessResponseWithHeaders(connectorId, mediaType,"/connector/{connectorId}/flow/start/{id}","started flow " + flowId,"started flow " + flowId,flowId);
}else {
throw new Exception(status);
Expand All @@ -360,6 +385,9 @@ public ResponseEntity<String> stopflow(@ApiParam(hidden = true) @RequestHeader(
flowId = id.toString();
status = connector.stopFlow(flowId);
if(status.equals("stopped")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:stopped");
}
return ResponseUtil.createSuccessResponseWithHeaders(connectorId, mediaType,"/connector/{connectorId}/flow/stop/{id}","stopped flow " + flowId,"stopped flow " + flowId,flowId);
}else {
throw new Exception(status);
Expand All @@ -380,6 +408,9 @@ public ResponseEntity<String> restartflow(@ApiParam(hidden = true) @RequestHead
flowId = id.toString();
status = connector.restartFlow(flowId);
if(status.equals("started")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:restarted");
}
return ResponseUtil.createSuccessResponseWithHeaders(connectorId, mediaType,"/connector/{connectorId}/flow/restart/{id}","restarted","restarted flow " + flowId,flowId);
}else {
throw new Exception(status);
Expand All @@ -400,6 +431,9 @@ public ResponseEntity<String> pauseflow(@ApiParam(hidden = true) @RequestHeader
flowId = id.toString();
status = connector.pauseFlow(flowId);
if(status.equals("suspended") || status.equals("stopped")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:suspended");
}
return ResponseUtil.createSuccessResponseWithHeaders(connectorId, mediaType,"/connector/{connectorId}/flow/pause/{id}","paused","paused flow " + flowId,flowId);
}else {
throw new Exception(status);
Expand All @@ -420,6 +454,9 @@ public ResponseEntity<String> resumeflow(@ApiParam(hidden = true) @RequestHeader
flowId = id.toString();
status = connector.resumeFlow(flowId);
if(status.equals("started")) {
if(this.messagingTemplate!=null) {
this.messagingTemplate.convertAndSend("/topic/" + flowId + "/event","event:resumed");
}
return ResponseUtil.createSuccessResponseWithHeaders(connectorId, mediaType,"/connector/{connectorId}/flow/resume/{id}","resumed","resumed flow " + flowId,flowId);
}else {
throw new Exception(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public class EnvironmentResource {
*/
@PostMapping(path = "/environment/{gatewayid}", consumes = {"text/plain","application/xml", "application/json"}, produces = {"text/plain","application/xml", "application/json"})
@Timed
public ResponseEntity<String> setGatewayConfiguration(@ApiParam(hidden = true) @RequestHeader("Accept") String mediaType, @PathVariable Long gatewayid, @RequestBody String configuration) throws Exception {
public ResponseEntity<String> setGatewayConfiguration(@ApiParam(hidden = true) @RequestHeader("Accept") String mediaType,@ApiParam(hidden = true) @RequestHeader("Content-Type") String contentType, @PathVariable Long gatewayid, @RequestBody String configuration) throws Exception {

try {
DBConfiguration.convertConfigurationToDB(gatewayid, mediaType, configuration);
DBConfiguration.convertConfigurationToDB(gatewayid, contentType, configuration);
return ResponseUtil.createSuccessResponse(gatewayid, mediaType, "setConfiguration", "Connector configuration set");
} catch (Exception e) {
return ResponseUtil.createFailureResponse(gatewayid, mediaType, "setConfiguration", e.getMessage());
Expand Down
Loading

0 comments on commit a16fd71

Please sign in to comment.