From 770021322f68b2f5ba249e5ba5cb6afab1560f1f Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 6 May 2011 13:24:17 +0000 Subject: hacks to help me think about what domain info is missing at the moment git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1100203 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/slaws/domain-view/build.xml | 54 ++++++++ sandbox/slaws/domain-view/pom.xml | 102 ++++++++++++++ .../apache/tuscany/sca/domain/interop/Domain.java | 145 ++++++++++++++++++++ .../apache/tuscany/sca/domain/interop/Tuscany.java | 152 +++++++++++++++++++++ .../main/resources/META-INF/sca-contribution.xml | 25 ++++ .../src/main/resources/domain.composite | 32 +++++ .../domain1/helloworld-client-contribution.jar | Bin 0 -> 9625 bytes .../domain1/helloworld-iface-contribution.jar | Bin 0 -> 8212 bytes .../domain1/helloworld-service-contribution.jar | Bin 0 -> 9432 bytes .../src/test/resources/domain1/nodeClient/node.xml | 39 ++++++ .../test/resources/domain1/nodeService/node.xml | 39 ++++++ 11 files changed, 588 insertions(+) create mode 100644 sandbox/slaws/domain-view/build.xml create mode 100644 sandbox/slaws/domain-view/pom.xml create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java create mode 100644 sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java create mode 100644 sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/slaws/domain-view/src/main/resources/domain.composite create mode 100644 sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-client-contribution.jar create mode 100644 sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-iface-contribution.jar create mode 100644 sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-service-contribution.jar create mode 100644 sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml create mode 100644 sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml (limited to 'sandbox/slaws') diff --git a/sandbox/slaws/domain-view/build.xml b/sandbox/slaws/domain-view/build.xml new file mode 100644 index 0000000000..684aa97ec8 --- /dev/null +++ b/sandbox/slaws/domain-view/build.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/slaws/domain-view/pom.xml b/sandbox/slaws/domain-view/pom.xml new file mode 100644 index 0000000000..9ddd29dc3c --- /dev/null +++ b/sandbox/slaws/domain-view/pom.xml @@ -0,0 +1,102 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-itest + 2.0-SNAPSHOT + + domain-view + Apache Tuscany SCA Domain View + + + + + org.apache.tuscany.sca + tuscany-base-runtime-pom + pom + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-sca-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-ws-runtime-axis2 + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-binding-rest-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-host-jetty + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-domain-hazelcast + 2.0-SNAPSHOT + + + + + org.apache.tuscany.sca + itest-nodes-helloworld-iface + 2.0-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + + + run-samples + test + + run + + + + + + + + + + + + + + diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java new file mode 100644 index 0000000000..a8625e91a2 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Domain.java @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.domain.interop; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +import org.oasisopen.sca.annotation.Service; +import org.apache.tuscany.sca.node.impl.NodeImpl; + +/** + * Some hand crafted HTTP code to help me think about what info is missing + * from the domain ragistry + * + */ +@Service(Domain.class) +public class Domain implements Servlet { + public String getDomainComposite(){ + NodeImpl node = (NodeImpl)Tuscany.node; + String domainComposite = node.dumpDomainComposite(); + return domainComposite; + } + + public String getComponent(){ + NodeImpl node = (NodeImpl)Tuscany.node; + String domainComposite = node.dumpDomainComposite(); + return domainComposite; + } + + public void init(ServletConfig config) throws ServletException { + } + + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + HttpServletRequest httpRequest = (HttpServletRequest)request; + ServletOutputStream os = response.getOutputStream(); + + String pathInfo = httpRequest.getPathInfo(); + + if (pathInfo == null || pathInfo.length() < 1){ + os.print("

URL should include at least a domain name, e.g. http://localhost/sca/mydomain"); + return; + } + + pathInfo = pathInfo.substring(1); + String[] pathElements = pathInfo.split("/"); + + String domainName = pathElements[0]; + String action = "none"; + + if (pathElements.length == 2){ + action = pathElements[1]; + } + + // Just some hand crafted code to help me visualize resources + os.print(""); + + if ( action.equals("composite")){ + String domainComposite = getDomainComposite(); + domainComposite = domainComposite.replaceAll("<", "<"); + domainComposite = domainComposite.replaceAll(">", ">"); + os.print("

" + domainComposite + ""); + return; + } else { + try { + File domainDir = new File("target/test-classes/" + domainName); + + URI domainDirURI = domainDir.toURI(); + URI domainResourceURI = domainDirURI.resolve(pathInfo); + + os.print("

contributions"); + + for (File subDir : domainDir.listFiles()){ + if (!subDir.isDirectory()){ + os.print("

" + subDir.getName()); + } + } + + os.print("

nodes"); + os.print("

domainComposite"); + + os.print(""); + + return; + } catch (Exception ex){ + ex.printStackTrace(); + } + } + + os.print("

no processing"); + + } + + public void destroy() { + } + + public ServletConfig getServletConfig() { + return null; + } + + public String getServletInfo() { + return null; + } + + public void writeResource(ServletOutputStream os, URL url) throws Exception { + URLConnection connection = url.openConnection(); + connection.setUseCaches(false); + + InputStream is = connection.getInputStream(); + int aChar; + while(( aChar = is.read()) != -1){ + os.write(aChar); + } + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java new file mode 100644 index 0000000000..bafd818355 --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/interop/Tuscany.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.domain.interop; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +/** + * Main class for Tuscany. Just looking at what it means to read config from a directory structure. + * + */ +public class Tuscany { + + public static Node node = null; + private static Node domain = null; + + public static void main(String[] args) throws Exception { + String domainName = args[0]; + String nodeName = args[1]; + int deamonPort = -1; + + if (args.length > 2){ + deamonPort = Integer.parseInt(args[2]); + } + + // find the domain directory + File currentDirectory = new File("."); + File domainDirectory = findDirectory(currentDirectory, domainName); + System.out.println("Domain: " + domainDirectory.getPath()); + + // find a sub directory that ends in nodeName + File nodeDirectory = findDirectory(currentDirectory, nodeName); + System.out.println("Node: " + nodeDirectory.getPath()); + + // start a node with the node configuration +/* don't know how to start the node using the following + TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); + Node node = tuscanyRuntime.createNodeFromXML(nodeDirectory.getPath() + + File.separator + + "node.xml"); +*/ + NodeFactory nodeFactory = NodeFactory.newInstance(); + + // temporarily use the Tuscany runtime to expose domain services + // for looking at the domain in a RESTful way. Replace with more + // integrated code! + domain = nodeFactory.createNode(new Contribution("domain", "target/classes")); + domain.start(); + + URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL(); + node = nodeFactory.createNode(nodeConfigURL); + + + try { + node.start(); + + // Use ? to provide web access to the domain details. + + // for testing we're going to set up a deamon that listens for + // a shutdown message on a specified port (well it actually just + // waits for a client to connect to the port as that's all we need + // for now). If no port is specified then just stop straight away + + if (deamonPort >= 0){ + // Its a runtime that has to act as a deamon + ServerSocket serverSocket = null; + + try { + serverSocket = new ServerSocket(deamonPort); + } catch (IOException e) { + System.out.println("Can't create a ServerSocket on port: " + deamonPort); + return; + } + + // all we're doing here is waiting for a connection. If we wanted to implement + // a real deamon we should perhaps listen to what's coming in over the resulting socket + // and see if a shutdown has been requested + Socket clientSocket = null; + try { + clientSocket = serverSocket.accept(); + } catch (IOException e) { + System.out.println("Accept failed on port: " + deamonPort); + return; + } + } + + } finally { + node.stop(); + domain.stop(); + } + } + + /** + * Just walks down the tree (depth first) looking for a directory ending in the + * name. + */ + private static File findDirectory(File currentDirectory, String name){ + File directory = null; + + if (currentDirectory.getPath().endsWith(name)){ + directory = currentDirectory; + } else { + File[] subDirectories = currentDirectory.listFiles(new DirectoryFilter()); + for (File aDirectory : subDirectories) { + directory = findDirectory(aDirectory, name); + + if (directory != null){ + break; + } + } + } + + return directory; + } + + private static class DirectoryFilter implements FilenameFilter { + + public boolean accept(File dir, String name) { + if(new File(dir, name).isDirectory()) { + return true; + } + + return false; + } + } + +} \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml b/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..370fe9903c --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,25 @@ + + + + + + + diff --git a/sandbox/slaws/domain-view/src/main/resources/domain.composite b/sandbox/slaws/domain-view/src/main/resources/domain.composite new file mode 100644 index 0000000000..316c1693ec --- /dev/null +++ b/sandbox/slaws/domain-view/src/main/resources/domain.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-client-contribution.jar b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-client-contribution.jar new file mode 100644 index 0000000000..c98214fc83 Binary files /dev/null and b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-client-contribution.jar differ diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-iface-contribution.jar b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-iface-contribution.jar new file mode 100644 index 0000000000..455de9c58a Binary files /dev/null and b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-iface-contribution.jar differ diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-service-contribution.jar b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-service-contribution.jar new file mode 100644 index 0000000000..28e3e680e9 Binary files /dev/null and b/sandbox/slaws/domain-view/src/test/resources/domain1/helloworld-service-contribution.jar differ diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml new file mode 100644 index 0000000000..81f82a9590 --- /dev/null +++ b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeClient/node.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml new file mode 100644 index 0000000000..2bb0bc7558 --- /dev/null +++ b/sandbox/slaws/domain-view/src/test/resources/domain1/nodeService/node.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3