-
Notifications
You must be signed in to change notification settings - Fork 0
Home
ssh ssh.api.no sh /nfs-home/home/pea/test.sh
Spring Boot with Docker https://spring.io/guides/gs/spring-boot-docker/ install jar to local maven repo http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/ http://kielczewski.eu/2014/04/spring-boot-mvc-application/ freemarker @Bean(name="producer") public JmsTemplate jmsTemplate() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setDefaultDestination(new ActiveMQQueue(queueName)); jmsTemplate.setConnectionFactory(connectionFactory()); return jmsTemplate; } @Bean public ActiveMQConnectionFactory connectionFactory() { ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(); activeMQConnectionFactory.setBrokerURL(brokerURL); activeMQConnectionFactory.setUserName(userName); activeMQConnectionFactory.setPassword(password); return activeMQConnectionFactory; }
Banner Tool : http://patorjk.com/software/taag/#p=display&h=0&f=Big&t=Chiwa
System.getProperty("my-name");
java -Dserver.port=9999 -Dmy-name="chiwa kantawong" -jar zengcode-1.0-SNAPSHOT.jar
http://www.mkyong.com/java/how-to-execute-shell-command-from-java/
**
-
Created by chiwa on 10/13/15. */ public class ExecuteCommand {
public static void main(String[] args) { executeCommand("docker images"); }
private static void executeCommand(String command) { Process p; try { p = Runtime.getRuntime().exec(command); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine())!= null) { System.out.println(line); }
} catch (Exception e) { System.out.println("Comman not found-"); }
} }
http://www.siamxcite.com/answer_view.php?id_ques=1513
http://howtodoinjava.com/2014/04/04/how-to-use-predicate-in-java-8/
http://www.byteslounge.com/tutorials/java-8-predicates-and-functions
http://howtodoinjava.com/2014/04/04/how-to-use-predicate-in-java-8/
http://howtodoinjava.com/2014/05/05/base64-encoding-and-decoding-example-in-java-8/
http://stackoverflow.com/questions/26504913/spring-boot-with-jndi-data-source
@Bean public DataSource dataSource() { JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); DataSource dataSource = dataSourceLookup.getDataSource("java:comp/env/jdbc/MyDataSourceName"); return dataSource; }
http://viralpatel.net/blogs/spring-mvc-exception-handling-controlleradvice-annotation/
https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
server: port: 9090
spring: view: prefix: /WEB-INF/jsp/ suffix: .jsp
configuration location
java -Dspring.config.location=/home/chiwa/POC/application.yml -jar target/biotec-1.0-SNAPSHOT.jar
@Controller public class AdminController {
@Autowired private Environment env;
@RequestMapping("/index.html") public String index(Model model) { model.addAttribute("message", "Hello Pea, Server Listening on port : " + env.getProperty("server.port")); return "index"; }
@Controller public class AdminController {
@Autowired private Environment env;
public String test = "${server.port}";
@Autowired public void myPort(@Value("${server.port}") String protocol) { this.test = protocol; }
@RequestMapping("/index.html") public String index(Model model) { model.addAttribute("message", "Hello Pea, Server Listening on port : " + env.getProperty("server.port") + " : " + test ); return "index"; }
METRICS
http://christopher-batey.blogspot.com/2015/03/pushing-metrics-to-graphite-from-spring.html
http://kielczewski.eu/2015/01/application-metrics-with-spring-boot-actuator/
http://kielczewski.eu/2015/01/application-metrics-with-spring-boot-actuator/
Configuration Class
server: port: 9000
connection: username: admin remoteAddress: 192.168.1.1 server : dev : dev-server production : prod-server
@Component @ConfigurationProperties(prefix="connection.server") public class ServerConfiguration { private String dev; private String production;
public String getDev() { return dev; }
public void setDev(String dev) { this.dev = dev; }
public String getProduction() { return production; }
public void setProduction(String production) { this.production = production; } }
Metrict to Graphite
@Autowired private MetricRegistry metricRegistry;
@Bean public GraphiteReporter graphiteReporter() { Graphite graphite = new Graphite(new InetSocketAddress("localhost", 2003));
GraphiteReporter reporter = GraphiteReporter .forRegistry(metricRegistry).prefixedWith("Chiwa") .build(graphite);
reporter.start(1000, TimeUnit.MILLISECONDS); return reporter; }
com.codahale.metrics metrics-graphite 3.0.2 io.dropwizard.metrics metrics-core 3.1.2Rest Template
https://spring.io/guides/gs/consuming-rest/
package biz.betimes.utils;
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader;
/**
-
Created by chiwa on 10/27/15. */ public class ShellScriptAndFileOperation {
/**
-
Write Text File, if file is existed delete it first and then create new file.
-
@param filePath
-
@param fileName
-
@param content
-
@return */ public static boolean writeTextFile(String filePath, String fileName, String content) { try { if (!filePath.endsWith("/")) { filePath += "/"; } File file = new File(filePath + fileName); if (file.exists()) { file.delete(); } file.createNewFile(); FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); return true;
} catch (IOException e) { e.printStackTrace(); return false; } }
public static void executeCommand(String command) { Process p; try { p = Runtime.getRuntime().exec(command); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine())!= null) { System.out.println(line); } } catch (Exception e) { System.out.println("Command not found-"); }
}
/* public static void main(String[] args) { writeTextFile("/home/chiwa/POC/", "testme.sh", "#!/bin/bash\n" + "echo "================================ " \n" + "echo "================================ " \n" + "echo "================================ " \n" + "clear\n" + "\n" + "echo "The script starts now."\n" + "\n" + "pwd\n" + "pwdx\n" + "\n" + "ls\n" + "\n" + "hello\n" + "\n" + "echo "End."");
executeCommand("sh /home/chiwa/POC/testme.sh");
}*/
-
}
| _ \ |_ | / __ \ |_ | | ____| / | | |) | | | | | | | | | | | | | | _ < | | | | | | | | | __| | | | |) | | | | || | | | | |____ | |____ |/ |__| _/ || || __|
#!/bin/bash
clear
echo "-----------------The script starts now.--------------"
sleep 5
echo "Step 1......." >> status.txt
pwd
sleep 5 echo "Step 2......." >> status.txt
ls
sleep 5 echo "Step 3......." >> status.txt
echo "----------------------End----------------------------"
package biz.betimes.configuration;
import com.mchange.v2.c3p0.ComboPooledDataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration public class BiotecConfiguration {
@Bean @ConfigurationProperties(prefix = "config.datasource") public DataSource dataSource() { return new ComboPooledDataSource(); }
}
http://www.cyberciti.biz/tips/linux-running-commands-on-a-remote-host.html
ssh root@192.168.1.39 "cd /usr/data/; ./test.sh"
ssh ssh.api.no sh /nfs-home/home/pea/test.sh