Skip to content

Commit

Permalink
talend components implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlolling committed Aug 22, 2017
1 parent a6ea1f8 commit b757d6e
Show file tree
Hide file tree
Showing 26 changed files with 510 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
Expand Down
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>talend-karaf-jmx</name>
<name>talendcomp_tKarafService</name>
<comment></comment>
<projects>
</projects>
Expand Down
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.source=1.7
73 changes: 55 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,62 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.jlo.karaf.jmx</groupId>
<artifactId>jlo-karaf-jmx</artifactId>
<packaging>jar</packaging>
<groupId>de.jlo.talendcomp</groupId>
<artifactId>jlo-talendcomp-karaf-jmx</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>jlo-karaf-jmx</name>
<url>http://maven.apache.org</url>
<name>jlo-karaf-jmx</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<version>1.0</version>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>de.cimt.talendcomp</groupId>
<artifactId>cimt-talendcomp-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>tKarafServiceList</id>
<configuration>
<componentName>tKarafServiceList</componentName>
</configuration>
<goals>
<goal>component</goal>
</goals>
</execution>
<execution>
<id>tKarafServiceInstall</id>
<configuration>
<componentName>tKarafServiceInstall</componentName>
</configuration>
<goals>
<goal>component</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

import java.io.IOException;
import java.lang.management.MemoryUsage;
Expand Down Expand Up @@ -30,7 +30,8 @@ public class BaseClient {
private String jmxUser = null;
private String jmxPassword = null;
private MBeanServerConnection mBeanServerConnection = null;

private JMXConnector jmxConnector = null;

public String getJmxServiceUrl() {
return jmxServiceUrl;
}
Expand Down Expand Up @@ -77,10 +78,20 @@ public void connect() throws Exception {
mBeanServerConnection = null;
Map<String, String[]> environment = new HashMap<String, String[]>();
environment.put(JMXConnector.CREDENTIALS, new String[] { jmxUser, jmxPassword });
JMXConnector jmxConnector = connectWithTimeout(new JMXServiceURL(jmxServiceUrl), environment, 10000l);
jmxConnector = connectWithTimeout(new JMXServiceURL(jmxServiceUrl), environment, 10000l);
mBeanServerConnection = jmxConnector.getMBeanServerConnection();
}

public void close() {
if (jmxConnector != null) {
try {
jmxConnector.close();
} catch (IOException e) {
// ignore
}
}
}

private void checkConnection() throws Exception {
if (mBeanServerConnection == null) {
throw new Exception("Not connected. MBeanServerConnection is null.");
Expand Down Expand Up @@ -116,6 +127,7 @@ private static JMXConnector connectWithTimeout(final JMXServiceURL url, final Ma
final BlockingQueue<Object> mailbox = new ArrayBlockingQueue<Object>(1);
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(new Runnable() {
@Override
public void run() {
try {
JMXConnector connector = JMXConnectorFactory.connect(url, environment);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

public class KarafClient extends BaseClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -60,6 +60,19 @@ public void installTalendService(String groupId, String artifactId, String versi
}
}

public void uninstallTalendService(String artifactId) throws Exception {
logger.info("Uninstall Talend Service: artifactId=" + artifactId);
String featureName = artifactId + "-feature";
logger.info("Uninstall features...");
uninstallFeature(featureName);
logger.info("Done");
logger.info("Check feature list...");
List<ServiceFeature> list = fetchFeatures(featureName, true);
if (list.isEmpty() == false) {
throw new Exception("Uninstallation seems to be ok but we still find the feature in the list of the installed feature!");
}
}

public void installFeature(String featureName, String version) throws Exception {
String[] opParams = {
featureName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

import java.security.Permission;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

import javax.management.openmbean.CompositeData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jlo.karaf.jmx;
package de.jlo.talendcomp.karaf.jmx;

import static org.junit.Assert.assertTrue;

Expand All @@ -7,6 +7,10 @@

import org.junit.Test;

import de.jlo.talendcomp.karaf.jmx.KarafClient;
import de.jlo.talendcomp.karaf.jmx.KarafDeployer;
import de.jlo.talendcomp.karaf.jmx.ServiceFeature;

public class TestClient {

@Test
Expand Down Expand Up @@ -51,7 +55,7 @@ public void testListFeatures() throws Exception {
}

@Test
public void testInstallFeature() throws Exception {
public void testUnAndInstallFeature() throws Exception {
String host = "talendjobtest01.gvl.local";
int jmxPort = 44444;
int jstatdPort = 1099;
Expand All @@ -66,21 +70,16 @@ public void testInstallFeature() throws Exception {
assertTrue(true);
// check memory usage
KarafDeployer d = new KarafDeployer(c);
System.out.println("List initial features...");
List<ServiceFeature> list = d.fetchFeatures("_service_", true);
for (ServiceFeature f : list) {
System.out.println(f + "\n");
}
System.out.println("Add repo...");
d.addFeatureRepo("de.gvl","navi_service_uploaded_files-feature", "26.17.0");
System.out.println("Uninstall feature...");
d.uninstallFeature("navi_service_uploaded_files-feature");
System.out.println("Add repo...");
d.addFeatureRepo("de.gvl","navi_service_uploaded_files-feature", "26.17.0");
System.out.println("Install feature...");
d.installFeature("navi_service_uploaded_files-feature", "26.17.0");
System.out.println("List resulting features...");
list = d.fetchFeatures("_service_", true);
List<ServiceFeature> list = d.fetchFeatures("_service_", true);
for (ServiceFeature f : list) {
System.out.println(f + "\n");
System.out.println(f.getArtifactId() + "\t" + f.getVersion() + "\t : " + f.getBundles());
}
}

Expand All @@ -100,6 +99,7 @@ public void testInstallTalendService() throws Exception {
assertTrue(true);
// check memory usage
KarafDeployer d = new KarafDeployer(c);
d.uninstallTalendService("navi_service_uploaded_files");
d.installTalendService("de.gvl","navi_service_uploaded_files", "26.17.0");
}

Expand Down
Binary file added tKarafServiceInstall_icon32.pxi
Binary file not shown.
Binary file added tKarafService_icon32.pxi
Binary file not shown.
17 changes: 17 additions & 0 deletions talend_component/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>COMPONENT_PROJECT</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%@ jet
imports="
org.talend.designer.codegen.config.CodeGeneratorArgument
org.talend.core.model.process.INode
org.talend.core.model.process.ElementParameterParser
org.talend.core.model.process.IConnection
org.talend.core.model.process.IConnectionCategory
org.talend.core.model.utils.NodeUtil
java.util.List
java.util.Map
"
%>
<%
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode) codeGenArgument.getArgument();
String cid = node.getUniqueName();
boolean isKaraf = "true".equals(ElementParameterParser.getValue(node, "__IS_KARAF__"));
String jmxUrl = ElementParameterParser.getValue(node, "__JMX_URL__");
String jmxUser = ElementParameterParser.getValue(node, "__JMX_USER__");
String jmxPassword = ElementParameterParser.getValue(node, "__JMX_PASSWORD__");
String server = ElementParameterParser.getValue(node, "__KARAF_SERVER__");
String instance = ElementParameterParser.getValue(node, "__KARAF_INSTANCE__");
String jmxPort = ElementParameterParser.getValue(node, "__JMX_PORT__");
String jstatdPort = ElementParameterParser.getValue(node, "__JSTATD_PORT__");
%>
de.jlo.talendcomp.karaf.jmx.KarafClient client_<%=cid%> = new de.jlo.talendcomp.karaf.jmx.KarafClient();
client_<%=cid%>.setJmxUser(<%=jmxUser%>);
client_<%=cid%>.setJmxPassword(<%=jmxPassword%>);
<% if (isKaraf) { %>
client_<%=cid%>.setKarafRemoteJmxUrl(<%=server%>, <%=jmxPort%>, <%=instance%>, <%=jstatdPort%>);
<% } else { %>
client_<%=cid%>.setJmxUrl(<%=jmxUrl%>);
<% } %>
try {
client_<%=cid%>.connect();
} catch (Exception e) {
globalMap.put("<%=cid%>_ERROR_MESSAGE", "Connect to jmx failed: " + e.getMessage());
throw new Exception("Connect to jmx failed: URL: " + client_<%=cid%>.getJmxServiceUrl(), e);
}
de.jlo.talendcomp.karaf.jmx.KarafDeployer <%=cid%> = new de.jlo.talendcomp.karaf.jmx.KarafDeployer(client_<%=cid%>);
int countInstall_<%=cid%> = 0;
int countUninstall_<%=cid%> = 0;
int countFailures_<%=cid%> = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%@ jet
imports="
org.talend.core.model.process.INode
org.talend.designer.codegen.config.CodeGeneratorArgument
"
%>
<%
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode) codeGenArgument.getArgument();
String cid = node.getUniqueName(); %>
client_<%=cid%>.close();
globalMap.put("<%=cid%>_NB_LINE_INSTALL", countInstall_<%=cid%>);
globalMap.put("<%=cid%>_NB_LINE_UNINSTALL", countUninstall_<%=cid%>);
globalMap.put("<%=cid%>_NB_LINE_FAILURES", countFailures_<%=cid%>);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b757d6e

Please sign in to comment.