Skip to content

Commit

Permalink
Changes for setting/using base directory in connector
Browse files Browse the repository at this point in the history
  • Loading branch information
assimbly committed Jan 18, 2020
1 parent e4b5bcc commit 02c67f7
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.

This file was deleted.

34 changes: 28 additions & 6 deletions src/main/java/org/assimbly/gateway/GatewayApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.assimbly.gateway.config.ApplicationProperties;
import org.assimbly.gateway.config.DefaultProfileUtil;
import org.assimbly.gateway.config.ApplicationProperties.Gateway;

import io.github.jhipster.config.JHipsterConstants;

Expand Down Expand Up @@ -29,6 +30,8 @@ public class GatewayApp {

private static final Logger log = LoggerFactory.getLogger(GatewayApp.class);

private final static String userHomeDir = System.getProperty("user.home");

private final Environment env;

public GatewayApp(Environment env) {
Expand Down Expand Up @@ -84,30 +87,49 @@ private static void logApplicationStartup(Environment env) {
log.warn("The host name could not be determined, using `localhost` as fallback");
}


String applicationName = "Assimbly " + env.getProperty("spring.application.name");
String applicationVersion = env.getProperty("application.info.version");
String applicationBaseDirectory = env.getProperty("application.gateway.base-directory");
String javaVersion = Runtime.class.getPackage().getImplementationVersion();
String javaWorkingDirectory = Paths.get(".").toAbsolutePath().normalize().toString();

if(applicationBaseDirectory.equals("default")) {
if(isWindows()) {
applicationBaseDirectory = userHomeDir + "\\build";
}else {
applicationBaseDirectory = userHomeDir + "/build";
}
}

log.info("\n----------------------------------------------------------\n\t" +
"Application 'Assimbly {}' is running! \n\n\t" +
"Application '{}' is running! \n\n\t" +
"Application Version: \t{}\n\t" +
"Application BaseDir: \t{}\n\t" +
"Local URL: \t\t{}://localhost:{}{}\n\t" +
"External URL: \t\t{}://{}:{}{}\n\t" +
"Application Version: \t{}\n\t" +
"Java Version: \t\t{}\n\t" +
"Java WorkingDir: \t{}\n\t" +
"Java WorkingDir: \t{}\n\t" +
"Profile(s): \t\t{}\n----------------------------------------------------------",
env.getProperty("spring.application.name"),
applicationName,
applicationVersion,
applicationBaseDirectory,
protocol,
serverPort,
contextPath,
protocol,
hostAddress,
serverPort,
contextPath,
env.getProperty("application.info.version"),
javaVersion,
javaWorkingDirectory,
env.getActiveProfiles());

}

public static boolean isWindows()
{
String OS = System.getProperty("os.name");
return OS.startsWith("Windows");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void setCamelUrl(String camelUrl) {
public static class Gateway {

private String name;
private String baseDirectory;

public String getName() {
return name;
Expand All @@ -76,7 +77,14 @@ public String getName() {
public void setName(String name) {
this.name = name;
}


public String getBaseDirectory() {
return baseDirectory;
}

public void setBaseDirectory(String baseDirectory) {
this.baseDirectory = baseDirectory;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ public String getCamelLink() {

@GetMapping("/gateway-name")
public String getGatewayName() {
Gateway gatway = applicationProperties.getGateway();
return gatway.getName();
Gateway gateway = applicationProperties.getGateway();
return gateway.getName();
}

@GetMapping("/gateway-base-directory")
public String getGatewayBaseDirectory() {
Gateway gateway = applicationProperties.getGateway();
return gateway.getBaseDirectory();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.assimbly.connector.Connector;
import org.assimbly.connector.impl.CamelConnector;
import org.assimbly.gateway.config.ApplicationProperties;
import org.assimbly.gateway.config.ApplicationProperties.Gateway;
import org.assimbly.gateway.config.environment.DBConfiguration;
import org.assimbly.gateway.domain.Flow;
import org.assimbly.gateway.event.FailureListener;
Expand All @@ -12,6 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.web.bind.annotation.*;
Expand All @@ -20,6 +23,7 @@
import com.codahale.metrics.annotation.Timed;

import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;
import java.util.TreeMap;
Expand All @@ -36,6 +40,8 @@
public class ConnectorResource {

private final Logger log = LoggerFactory.getLogger(ConnectorResource.class);

private final ApplicationProperties applicationProperties;

private Connector connector = new CamelConnector();

Expand Down Expand Up @@ -63,7 +69,9 @@ public class ConnectorResource {
@Autowired
private SimpMessageSendingOperations messagingTemplate;

public ConnectorResource() {}
public ConnectorResource(ApplicationProperties applicationProperties) {
this.applicationProperties = applicationProperties;
}

//configure connector (by gatewayid)

Expand Down Expand Up @@ -773,8 +781,16 @@ private void init() throws Exception {
if(!connector.isStarted() && !connectorIsStarting){
try {

Gateway gateway = applicationProperties.getGateway();
String applicationBaseDirectory = gateway.getBaseDirectory();

if(!applicationBaseDirectory.equals("default")) {
connector.setBaseDirectory(applicationBaseDirectory);
}

connectorIsStarting = true;
connector.addEventNotifier(failureListener);

connector.start();

int count = 1;
Expand Down Expand Up @@ -822,4 +838,12 @@ private void initConnector() {
}

}

public static boolean isWindows()
{
String OS = System.getProperty("os.name");
return OS.startsWith("Windows");
}


}
1 change: 1 addition & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ application:
camel-url: https://camel.apache.org/components/latest
gateway:
name: default
base-directory: default

hawtio:
authenticationEnabled: false
Binary file modified src/main/resources/keystore.jks
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- The FILE and ASYNC appenders are here as examples for a production configuration -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${user.home}/.assimbly/%d{yyyy-MM-dd}.assimbly.log</fileNamePattern>
<fileNamePattern>${user.home}/.assimbly/logs/%d{yyyy-MM-dd}.assimbly.log</fileNamePattern>
<maxHistory>90</maxHistory>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
Expand Down

0 comments on commit 02c67f7

Please sign in to comment.