diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/node-manager/src')
24 files changed, 1200 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java new file mode 100644 index 0000000000..8a1fab65b7 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java @@ -0,0 +1,39 @@ +/* + * 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.node.manager; + +import java.util.List; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +@Path("") +public interface DomainAssetManagerResource { + + @GET + @Path("{domainURI}/services/status") + List<Status> getServiceStatus(@PathParam("domainURI") @DefaultValue("default") String domainURI); + +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainCompositeResource.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainCompositeResource.java new file mode 100644 index 0000000000..f917ca3b99 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainCompositeResource.java @@ -0,0 +1,36 @@ +/* + * 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.node.manager; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +@Path("") +public interface DomainCompositeResource { + + @GET + @Path("{domainURI}") + String getDomainComposite(@PathParam("domainURI") @DefaultValue("default") String domainURI); +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Manageable.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Manageable.java new file mode 100644 index 0000000000..139e87c5f5 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Manageable.java @@ -0,0 +1,31 @@ +/* + * 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.node.manager; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface Manageable { + + /** + * isAlive method that allow service to be managed + */ + void isAlive(); +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java new file mode 100644 index 0000000000..75d25734d8 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Status.java @@ -0,0 +1,87 @@ +/* + * 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.node.manager; + +public class Status { + public static String OK ="ok"; + public static String WARNING = "warning"; + public static String CRITICAL = "critical"; + public static String UNAVAILABLE = "unavailable"; + + private String name; + private String uri; + private String status; + private String statusMessage; + private long execution; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + } + + public long getExecution() { + return execution; + } + + public void setExecution(long execution) { + this.execution = execution; + } + + @Override + public String toString() { + return "Status [name=" + name + + ", uri=" + + uri + + ", status=" + + status + + ", statusMessage=" + + statusMessage + + ", execution=" + + execution + + "]"; + } +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java new file mode 100644 index 0000000000..3935c75021 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java @@ -0,0 +1,160 @@ +/* + * 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.node.manager.impl; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.extensibility.NodeActivator; +import org.apache.tuscany.sca.node.extensibility.NodeExtension; +import org.apache.tuscany.sca.node.manager.DomainAssetManagerResource; +import org.apache.tuscany.sca.node.manager.Manageable; +import org.apache.tuscany.sca.node.manager.Status; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Property; +import org.oasisopen.sca.annotation.Scope; + +@Scope("COMPOSITE") +public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAssetManagerResource { + private static Map<String, NodeExtension> nodeMap = new ConcurrentHashMap<String,NodeExtension>(); + + @Property + private int warningThreshold; + + @Property + private int criticalThreshold; + + @Property + private int unavailableThreshold; + + public void nodeStarted(Node node) { + NodeExtension nodeExtension = (NodeExtension) node; + nodeMap.put(nodeExtension.getDomainURI(), nodeExtension); + } + + public void nodeStopped(Node node) { + NodeExtension nodeExtension = (NodeExtension) node; + nodeMap.remove(nodeExtension.getDomainURI()); + } + + @Init + public void init() { + System.out.println("Initializing Domain Asset Manager"); + System.out.println(" - Warning threshold : " + warningThreshold + " ms" ); + System.out.println(" - Critical threshold : " + criticalThreshold + " ms"); + System.out.println(" - Unavailable threshold : " + unavailableThreshold + " ms"); + + } + + @Override + public List<Status> getServiceStatus(@PathParam("domainURI") @DefaultValue("default") String domainURI) { + if( ! nodeMap.containsKey(domainURI)) { + throw new WebApplicationException(404); + } + + NodeExtension node = nodeMap.get(domainURI); + Composite domainComposite = node.getDomainComposite(); + + List<Status> statuses = new ArrayList<Status>(); + for(Component component : domainComposite.getComponents()) { + for(Service service : component.getServices()) { + Interface interfaceContract = service.getInterfaceContract().getInterface(); + if(Manageable.class.getName().equals(interfaceContract.toString())) { + + Status status = new Status(); + status.setName(component.getName()); + status.setUri(service.getBindings().get(0).getURI()); + + try { + String serviceName = component.getName() + "/" + service.getName(); + Manageable serviceInstance = node.getService(Manageable.class, serviceName); + Timer t = new Timer(); + serviceInstance.isAlive(); + status.setExecution(t.elapsed(TimeUnit.MILLISECONDS)); + + if(status.getExecution() < warningThreshold) { + status.setStatus(Status.OK); + }else if(status.getExecution() > warningThreshold) { + status.setStatus(Status.WARNING); + }else if(status.getExecution() > criticalThreshold) { + status.setStatus(Status.CRITICAL); + } else { + status.setStatus(Status.UNAVAILABLE); + } + } catch (Exception e) { + status.setStatus(Status.UNAVAILABLE); + status.setStatusMessage(e.getMessage()); + } + + statuses.add(status); + } + } + } + + return statuses; + } + + class Timer { + Date time; + long t; + + public Timer() { + reset(); + } + + public void reset() { + time = new Date(); + t = System.nanoTime(); + } + + public Date time() { + return time; + } + + public long elapsed(TimeUnit timeUnit) { + long elapsedTime = elapsed(); + return timeUnit.convert(elapsedTime, TimeUnit.NANOSECONDS); + } + + public void print(String s, TimeUnit timeUnit) { + long elapsedTime = elapsed(); + + System.out.println(s + ": " + timeUnit.convert(elapsedTime, TimeUnit.NANOSECONDS) + "ms"); + } + + private long elapsed() { + return System.nanoTime() - t; + } + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainCompositeResourceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainCompositeResourceImpl.java new file mode 100644 index 0000000000..9cb91e2917 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainCompositeResourceImpl.java @@ -0,0 +1,100 @@ +/* + * 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.node.manager.impl; + +import java.io.ByteArrayOutputStream; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.ws.rs.WebApplicationException; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.extensibility.NodeActivator; +import org.apache.tuscany.sca.node.extensibility.NodeExtension; +import org.apache.tuscany.sca.node.manager.DomainCompositeResource; + +public class DomainCompositeResourceImpl implements NodeActivator, DomainCompositeResource { + private static Map<String, NodeExtension> nodeMap = new ConcurrentHashMap<String,NodeExtension>(); + + public void nodeStarted(Node node) { + NodeExtension nodeExtension = (NodeExtension) node; + nodeMap.put(nodeExtension.getDomainURI(), nodeExtension); + } + + public void nodeStopped(Node node) { + NodeExtension nodeExtension = (NodeExtension) node; + nodeMap.remove(nodeExtension.getDomainURI()); + } + + public String getDomainComposite(String domainURI) { + if( ! nodeMap.containsKey(domainURI)) { + throw new WebApplicationException(404); + } + + NodeExtension node = nodeMap.get(domainURI); + Composite composite = node.getDomainComposite(); + + //set name, as it's empty by default + composite.setName(new QName("", "Domain")); + + ExtensionPointRegistry registry = node.getExtensionPointRegistry(); + StAXArtifactProcessorExtensionPoint xmlProcessors = + registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor<Composite> compositeProcessor = + xmlProcessors.getProcessor(Composite.class); + + return writeComposite(composite, registry, compositeProcessor); + } + + + private String writeComposite(Composite composite, ExtensionPointRegistry registry, StAXArtifactProcessor<Composite> compositeProcessor){ + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + XMLOutputFactory outputFactory = + registry.getExtensionPoint(FactoryExtensionPoint.class) + .getFactory(XMLOutputFactory.class); + + try { + compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(registry)); + } catch(Exception ex) { + return ex.toString(); + } + + String result = bos.toString(); + + // write out and nested composites + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + result += "\n<!-- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -->\n" + + writeComposite((Composite)component.getImplementation(), registry, + compositeProcessor); + } + } + return result; + } +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivator b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivator new file mode 100644 index 0000000000..632f62d67c --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.extensibility.NodeActivator @@ -0,0 +1,19 @@ +# 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. +# Implementation class for the ModuleActivator +org.apache.tuscany.sca.node.manager.impl.DomainCompositeResourceImpl;ranking=100 +org.apache.tuscany.sca.node.manager.impl.DomainAssetManagerResourceImpl;ranking=101 diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java new file mode 100644 index 0000000000..cc288ea29a --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResourceTestCase.java @@ -0,0 +1,74 @@ +/* + * 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.node.manager; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +public class DomainAssetManagerResourceTestCase { + private static String SERVICE_URL; + private static Node node; + + + @BeforeClass + public static void init() throws Exception { + try { + String contribution = ContributionLocationHelper.getContributionLocation(DomainCompositeResourceTestCase.class); + node = NodeFactory.newInstance().createNode("node-asset-manager-test.composite", new Contribution("node-manager", contribution)); + node.start(); + + SERVICE_URL = node.getEndpointAddress("NodeAssetManagerComponent"); + + System.out.println(">>" + SERVICE_URL); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + if (node != null) { + node.stop(); + } + } + + + @Test + public void testServiceManagement() throws Exception { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(SERVICE_URL + "default/services/status"); + request.setHeaderField("Accept","application/json"); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + System.out.println(">>>" + response.getText()); + } +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainCompositeResourceTestCase.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainCompositeResourceTestCase.java new file mode 100644 index 0000000000..da50dca604 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/org/apache/tuscany/sca/node/manager/DomainCompositeResourceTestCase.java @@ -0,0 +1,80 @@ +/* + * 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.node.manager; + +import java.net.Socket; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.ContributionLocationHelper; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +@Ignore +public class DomainCompositeResourceTestCase { + private static final String SERVICE_URL = "http://localhost:8080/domain"; + + private static Node node; + + @BeforeClass + public static void init() throws Exception { + try { + String contribution = ContributionLocationHelper.getContributionLocation(DomainCompositeResourceTestCase.class); + node = NodeFactory.newInstance().createNode("node-manager-test.composite", new Contribution("node-manager", contribution)); + node.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void destroy() throws Exception { + if (node != null) { + node.stop(); + } + } + + @Test + public void testPing() throws Exception { + new Socket("127.0.0.1", 8080); + //System.in.read(); + } + + @Test + public void testDefaultDomainCompositeResource() throws Exception { + String url = SERVICE_URL + "/default"; + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest(url); + WebResponse response = wc.getResource(request); + + Assert.assertEquals(200, response.getResponseCode()); + System.out.println(">>>" + response.getText()); + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyResource.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyResource.java new file mode 100644 index 0000000000..74042d2561 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyResource.java @@ -0,0 +1,31 @@ +/* + * 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 services; + +import javax.ws.rs.GET; +import javax.ws.rs.core.Response; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface MyResource { + @GET + Response getSomething(); +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyService.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyService.java new file mode 100644 index 0000000000..4a1b34eead --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/MyService.java @@ -0,0 +1,28 @@ +/* + * 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 services; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface MyService { + + void doSomething(); +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyLongRunningResourceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyLongRunningResourceImpl.java new file mode 100644 index 0000000000..59e72f9fd5 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyLongRunningResourceImpl.java @@ -0,0 +1,48 @@ +/* + * 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 services.impl; + +import javax.ws.rs.core.Response; + +import org.apache.tuscany.sca.node.manager.Manageable; + +import services.MyResource; + +public class MyLongRunningResourceImpl implements MyResource, Manageable { + + @Override + public void isAlive() { + System.out.println(">>> long running ping"); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + + @Override + public Response getSomething() { + System.out.println(">>> getSomething"); + return Response.ok("something").build(); + } + + +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyOtherResourceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyOtherResourceImpl.java new file mode 100644 index 0000000000..421c8d92ec --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyOtherResourceImpl.java @@ -0,0 +1,30 @@ +/* + * 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 services.impl; + +import org.apache.tuscany.sca.node.manager.Manageable; + +public class MyOtherResourceImpl implements Manageable { + + @Override + public void isAlive() { + System.out.println(">>> isAlive"); + } +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyResourceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyResourceImpl.java new file mode 100644 index 0000000000..692f4ddb50 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyResourceImpl.java @@ -0,0 +1,41 @@ +/* + * 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 services.impl; + +import javax.ws.rs.core.Response; + +import services.MyResource; +import org.apache.tuscany.sca.node.manager.Manageable; + +public class MyResourceImpl implements MyResource, Manageable { + + @Override + public Response getSomething() { + System.out.println(">>> getSomething"); + return Response.ok("something").build(); + } + + + @Override + public void isAlive() { + System.out.println(">>> isAlive"); + } + +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyServiceImpl.java b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyServiceImpl.java new file mode 100644 index 0000000000..0bf675549f --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/java/services/impl/MyServiceImpl.java @@ -0,0 +1,37 @@ +/* + * 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 services.impl; + +import services.MyService; +import org.apache.tuscany.sca.node.manager.Manageable; + +public class MyServiceImpl implements MyService, Manageable { + + + @Override + public void isAlive() { + System.out.println(">>> isAlive"); + } + + @Override + public void doSomething() { + System.out.println(">>> doSomething"); + } +} diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-asset-manager-test.composite b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-asset-manager-test.composite new file mode 100644 index 0000000000..69bc8bd0da --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-asset-manager-test.composite @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://node-manager" + name="NodeAssetManager"> + + <component name="NodeAssetManagerComponent"> + <implementation.java class="org.apache.tuscany.sca.node.manager.impl.DomainAssetManagerResourceImpl"/> + <service name="DomainAssetManagerResource"> + <tuscany:binding.rest uri="/services/manager" /> + </service> + <property name="warningThreshold">100</property> <!-- 1s --> + <property name="criticalThreshold">30000</property> <!-- 30s --> + <property name="unavailableThreshold">60000</property> <!-- 1m --> + </component> + + <component name="Resource"> + <implementation.java class="services.impl.MyResourceImpl"/> + </component> + + <component name="LongRunningResource"> + <implementation.java class="services.impl.MyLongRunningResourceImpl"/> + </component> + + <component name="OtherResource"> + <implementation.java class="services.impl.MyOtherResourceImpl"/> + </component> + + + <component name="Service"> + <implementation.java class="services.impl.MyServiceImpl"/> + </component> +</composite> diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-manager-test.composite b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-manager-test.composite new file mode 100644 index 0000000000..6f107a392d --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/node-manager-test.composite @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://node-manager" + name="NodeManager"> + + <component name="NodeManagerUI"> + <tuscany:implementation.widget location="ui/index.html" /> + <service name="Widget"> + <tuscany:binding.rest uri="/manager/ui" /> + </service> + </component> + + <component name="NodeManagerComponent"> + <implementation.java class="org.apache.tuscany.sca.node.manager.impl.DomainCompositeResourceImpl"/> + <service name="DomainCompositeResource"> + <tuscany:binding.rest uri="/domain"> + <tuscany:operationSelector.jaxrs /> + </tuscany:binding.rest> + </service> + </component> +</composite> diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/component.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/component.gif Binary files differnew file mode 100644 index 0000000000..46b8963f4c --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/component.gif diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/composite.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/composite.gif Binary files differnew file mode 100644 index 0000000000..6749240e15 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/composite.gif diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/index.html b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/index.html new file mode 100644 index 0000000000..4405422c53 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/index.html @@ -0,0 +1,268 @@ +<!-- + * 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. +--> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Tuscany SCA Domain Components</title> + +<script type="text/javascript" src="/dojo/dojo.js"></script> + +<style type="text/css"> +body,html { + font-family: helvetica, arial, sans-serif; + font-size: 90%; +} + +.componentIcon { + margin-left: 16px; + width: 16px; + height: 16px; + background: url('component.gif') no-repeat; +} + +.serviceIcon { + margin-left: 16px; + width: 16px; + height: 16px; + background: url('service.gif') no-repeat; +} + +.referenceIcon { + margin-left: 16px; + width: 16px; + height: 16px; + background: url('reference.gif') no-repeat; +} +</style> + +</head> + +<body> + <div id="header" style="border-bottom: solid 1px silver; overflow: hidden;"> + <img src="http://tuscany.apache.org/images/TuscanyLogo.jpg" style="float:right;"/> + <h1>Tuscany SCA Domain</h1> + </div> <!-- end header div --> + + <div id="container" style="border:1px solid silver"> + <div id="navigation" style="position:absolute; float:left; width:30%; height:80%; padding:10px; border:1px solid silver"> + <div id="treeDomain" /> </div> + </div> <!-- end navigation div --> + + <div id="images" style="position:absolute; float:left; width:60%; height:80%; left:35%; padding:10px; border:1px solid silver"> + + <table style="margin-left:auto; margin-right:auto;" border="0" cellspacing="0" cellpadding="1"> + <tr> + <td><a href="javascript:updatePage(-1)">prev</a></td> + <td><a href="javascript:updatePage(1)">next</a></td> + </tr> + <tr> + <td colspan="4"> + <table id="tableImageThumb" style="margin-left:auto; margin-right:auto;" border="0" cellspacing="0" cellpadding="1"></table> + + </td> + </tr> + </table> + </div> <!-- end images div --> + + </div> <!-- end container div --> + +</body> + +<script type="text/javascript"> + dojo.require("dojo.data.ItemFileWriteStore"); + dojo.require("dijit.Tree"); + dojo.require("dojox.xml.parser"); + dojo.require("tuscany.RestService"); + //dojo.require("tuscany.Composite"); + + var restClient; + + var store; + var treeModel; + var treeControl; + + var composite; + + + function prepare() { + store = new dojo.data.ItemFileWriteStore({ + data: { + identifier: 'id', + label: 'label', + type: 'type', + items: [ ] + } + }); + treeModel = new dijit.tree.ForestStoreModel({ + store: store + }); + + treeControl = new dijit.Tree({ + model: treeModel, + showRoot: false, + getIconClass: function(/*dojo.data.Item*/ item, /*Boolean*/ opened) { + console.log("##" + item.type); + if(item.type != undefined) { + if(item.type == 'component') { + return "componentIcon"; + } else if(item.type == 'service' || item.type == 'service-binding') { + return "serviceIcon"; + } else if(item.type == 'reference' || item.type == 'reference-binding') { + return "referenceIcon"; + } + } + return "serviceIcon"; + }, + onClick: showArtifactDocumentation, + _createTreeNode: function(/*Object*/ args) { + var tnode = new dijit._TreeNode(args); + tnode.labelNode.innerHTML = args.label; + return tnode; + } + },"treeDomain"); + + restClient = new tuscany.RestService("/domain","text/plain"); + + showDomainArtifacts(); + } + + + function composite_getResponse(xmlResponse, exception) { + if(exception){ + alert(exception.message); + return; + } + + var componentNode = xmlResponse.getElementsByTagName ("component"); + //loop trough all components + for (c = 0; c < componentNode.length; c++) { + var componentAttributes = componentNode[c].attributes; + var componentItem = store.newItem({id:componentAttributes['uri'].value, label:componentAttributes['name'].value, type:'component'}); + + //loop trough all services + var serviceNode = componentNode[c].getElementsByTagName ("service"); + for(s = 0; s < serviceNode.length; s++) { + var serviceAttributes = serviceNode[s].attributes; + var serviceId = componentAttributes['uri'].value + "/" + serviceAttributes['name'].value; + + var parentInfo={ + parent: componentItem, + attribute: "children" + }; + + var serviceItem = store.newItem({id:serviceId, label:serviceAttributes['name'].value, type:'service'}, parentInfo); + + //loop trough children to find bindings + for(b=0; b < serviceNode[s].childNodes.length; b ++) { + var childNode = serviceNode[s].childNodes[b]; + if(childNode.nodeName.indexOf('binding') == 0) { + var bindingId = serviceId + "/" + childNode.nodeName; + + var parentInfo={ + parent: serviceItem, + attribute: "children" + }; + + var bindingItem = store.newItem({id:bindingId, label:childNode.nodeName, type:'service-binding'}, parentInfo); + } + } + } + + + //loop trough all references + var referenceNode = componentNode[c].getElementsByTagName ("reference"); + for(r = 0; r < referenceNode.length; r++) { + var referenceAttributes = referenceNode[r].attributes; + var referenceId = componentAttributes['uri'].value + "/" + referenceAttributes['name'].value; + + var parentInfo={ + parent: componentItem, + attribute: "children" + }; + + var referenceItem = store.newItem({id:serviceId, label:referenceAttributes['name'].value, type:'reference'}, parentInfo); + + //loop trough children to find bindings + for(b=0; b < referenceNode[s].childNodes.length; b ++) { + var childNode = referenceNode[s].childNodes[b]; + if(childNode.nodeName.indexOf('binding') == 0) { + var bindingId = serviceId + "/" + childNode.nodeName; + + var parentInfo={ + parent: serviceItem, + attribute: "children" + }; + + var bindingItem = store.newItem({id:bindingId, label:childNode.nodeName, type:'reference-binding'}, parentInfo); + } + } + + + } + + } + + //var composite = new tuscany.Composite(xmlResponse); + + + /* + var itemTags = xmlResponse.getElementsByTagName ("component"); + for (i = 0; i < itemTags.length; i++) { + var attributes = itemTags[i].attributes; + alert(attributes[0].name); + var recordNode = itemTags[i].getElementsByTagName ("name")[0]; + if (recordNode.textContent != undefined) { + alert(recordNode.textContent); + } + else { + alert(recordNode.text); + } + } + */ + + compositeXML = dojox.xml.parser.innerXML(xmlResponse); + + + //alert(compositeXML); + + } + + function showDomainArtifacts() { + restClient.get("default").addCallback(composite_getResponse); + } + + function showArtifactDocumentation(/*dojo.data.Item*/ item) { + alert('showing documentation for' + item.id); + } + + function guidGenerator() { + var S4 = function() { + return (((1+Math.random())*0x10000)|0).toString(16).substring(1); + }; + return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); + } + + + dojo.addOnLoad(prepare); +</script> + +</body> + +</html> diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/interface.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/interface.gif Binary files differnew file mode 100644 index 0000000000..1d11c37913 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/interface.gif diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/property.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/property.gif Binary files differnew file mode 100644 index 0000000000..354ad64645 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/property.gif diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/reference.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/reference.gif Binary files differnew file mode 100644 index 0000000000..b3e2c80188 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/reference.gif diff --git a/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/service.gif b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/service.gif Binary files differnew file mode 100644 index 0000000000..9b986e3788 --- /dev/null +++ b/sca-java-2.x/branches/2.0/modules/node-manager/src/test/resources/ui/service.gif |