summaryrefslogtreecommitdiffstats
path: root/sandbox/slaws/domain-view/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/slaws/domain-view/src/main/java/org')
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java47
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java40
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java85
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java90
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java56
-rw-r--r--sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java133
6 files changed, 451 insertions, 0 deletions
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java
new file mode 100644
index 0000000000..8163f160aa
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Composite.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface Composite {
+
+ @GET
+ @Produces( {MediaType.TEXT_HTML})
+ @Path("{domainname}/composite")
+ public String get();
+
+
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ @Path("{domainname}/composite/{compositename}")
+ public String getComposite(@PathParam("compositename") String domainName);
+
+} \ No newline at end of file
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java
new file mode 100644
index 0000000000..1011a5b693
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeImpl.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+/**
+ * Some hand crafted HTTP code to help me think about what info is missing
+ * from the domain registry
+ *
+ */
+public class CompositeImpl implements Composite {
+
+ public String get() {
+ String outputHTML = "<p/>get";
+ return outputHTML;
+ }
+
+
+ public String getComposite(String domainName) {
+ String outputHTML = "<p/>get composite";
+ return outputHTML;
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java
new file mode 100644
index 0000000000..773e649202
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Domain.java
@@ -0,0 +1,85 @@
+/*
+ * 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;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface Domain {
+
+ @GET
+ @Produces( {MediaType.TEXT_HTML})
+ public String get();
+
+ @Path("{domainname}")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getDomainServiceDocument(@PathParam("domainname") String domainName);
+
+ @Path("{domainname}/contribution")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getContributions(@PathParam("domainname") String domainName);
+
+ @Path("{domainname}/composite")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getComposites(@PathParam("domainname") String domainName);
+
+ @Path("{domainname}/component")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getComponents(@PathParam("domainname") String domainName);
+
+ @Path("{domainname}/endpoints")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getEndpoints(@PathParam("domainname") String domainName);
+
+ @Path("{domainname}/node")
+ @GET
+ @Produces( {MediaType.APPLICATION_ATOM_XML,
+ MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML,
+ MediaType.TEXT_HTML})
+ public String getNodes(@PathParam("domainname") String domainName);
+
+} \ No newline at end of file
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java
new file mode 100644
index 0000000000..41ca341763
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainImpl.java
@@ -0,0 +1,90 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.tuscany.sca.impl.NodeImpl;
+
+
+/**
+ * Some hand crafted HTTP code to help me think about what info is missing
+ * from the domain registry
+ *
+ */
+public class DomainImpl implements Domain {
+
+ public String get() {
+ String outputHTML = "<p/>enter URL in the form http://host:port/sca/domain/yourdomainnamehere";
+ return outputHTML;
+ }
+
+ public String getDomainServiceDocument(String domainName) {
+ String outputHTML = "<p/><a href=\"" + domainName + "/contribution\">contributions</a>" +
+ "<p/><a href=\"" + domainName + "/composite\">composites</a>" +
+ "<p/><a href=\"" + domainName + "/endpoint\">endpoints</a>" +
+ "<p/><a href=\"" + domainName + "/node\">nodes</a>";
+ return outputHTML;
+ }
+
+ public String getContributions(String domainName) {
+ NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode;
+ List<String> contributions = node.getInstalledContributionURIs();
+ return contributions.toString();
+ }
+
+ public String getComposites(String domainName){
+ NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode;
+ return node.getDomainLevelCompositeAsString();
+ }
+
+ public String getComponents(String domainName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getEndpoints(String domainName) {
+ NodeImpl node = (NodeImpl)DomainView.domainAccessPointNode;
+ return node.getEndpointRegistry().getEndpoints().toString();
+ }
+
+ public String getNodes(String domainName){
+ // use the domain on the file system in lieu of info in the registry
+ File domainDir = new File("target/test-classes/" + domainName);
+ String nodes = "";
+
+ for (File subDir : domainDir.listFiles()){
+ if (subDir.isDirectory()){
+ nodes += subDir.getName() + "\n";
+ }
+ }
+ return nodes;
+ }
+
+ // utilities
+
+ public String prettyPrintXMLString(String inXML){
+ return inXML.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+
+ // etc. need to read and write a structured version
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java
new file mode 100644
index 0000000000..e8d9aa416a
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/DomainView.java
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+import org.apache.tuscany.sca.Node;
+import org.apache.tuscany.sca.TuscanyRuntime;
+
+/**
+ * Main class for Tuscany. Just looking at what it means to read config from a directory structure.
+ *
+ */
+public class DomainView {
+
+ public static Node domainAccessPointNode = null;
+ private static Node domainViewNode = null;
+
+ public static void main(String[] args) throws Exception {
+ String domainName = args[0];
+
+ TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+ // a node to access the specified domain
+ domainAccessPointNode = tuscanyRuntime.createNode("uri:" + domainName);
+
+ // a node to run the domain view app. Just starts in the local domain "domainview"
+ domainViewNode = tuscanyRuntime.createNode("domainview");
+ domainViewNode.installContribution("target/classes");
+
+ System.out.print("Press a key to stop");
+ try{
+ System.in.read();
+ } catch(Exception ex){
+ // do nothing
+ }
+
+ domainViewNode.stop();
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java
new file mode 100644
index 0000000000..81687f9e5c
--- /dev/null
+++ b/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/Tuscany.java
@@ -0,0 +1,133 @@
+/*
+ * 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;
+
+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;
+import org.apache.tuscany.sca.TuscanyRuntime;
+
+/**
+ * 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;
+
+ 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());
+
+ TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance();
+
+ URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL();
+ node = tuscanyRuntime.createNodeFromXML(nodeConfigURL.toString());
+
+ try {
+ //node.start();
+
+ // 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();
+ }
+ }
+
+ /**
+ * 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