From b8dde41d9e03a4d15b03995c65bd5416d4d9a216 Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 5 Apr 2012 23:19:16 +0000 Subject: Enhancing manageable interface, going back to manage all resources via sca, as resource programming model is getting too complicated and this should be easy for developers git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1310128 13f79535-47bb-0310-9956-ffa450edef68 --- .../node/manager/DomainAssetManagerResource.java | 7 +- .../tuscany/sca/node/manager/Manageable.java | 31 ++++++ .../sca/node/manager/ManageableResource.java | 41 ------- .../sca/node/manager/ManageableService.java | 31 ------ .../impl/DomainAssetManagerResourceImpl.java | 118 +-------------------- 5 files changed, 36 insertions(+), 192 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Manageable.java delete mode 100644 sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableResource.java delete mode 100644 sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableService.java (limited to 'sca-java-2.x/trunk/modules/node-manager/src/main') diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java index 3b123ab954..8a1fab65b7 100644 --- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java +++ b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/DomainAssetManagerResource.java @@ -30,12 +30,7 @@ import org.oasisopen.sca.annotation.Remotable; @Remotable @Path("") -public interface DomainAssetManagerResource { - - @GET - @Path("{domainURI}/resources/status") - List getResourceStatus(@PathParam("domainURI") @DefaultValue("default") String domainURI); - +public interface DomainAssetManagerResource { @GET @Path("{domainURI}/services/status") diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/Manageable.java b/sca-java-2.x/trunk/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/trunk/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/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableResource.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableResource.java deleted file mode 100644 index 36051c3908..0000000000 --- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableResource.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.oasisopen.sca.annotation.Remotable; - -@Remotable -public interface ManageableResource { - - /** - * Ping resource used for service monitoring - * @return - */ - @GET - @Path("/ping") - @Produces(MediaType.TEXT_HTML) - Response ping(); -} diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableService.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableService.java deleted file mode 100644 index 17ab866f44..0000000000 --- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/ManageableService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 ManageableService { - - /** - * isAlive method that allow service to be managed - */ - void isAlive(); -} diff --git a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java index ae55aab919..7d41bf80a2 100644 --- a/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java +++ b/sca-java-2.x/trunk/modules/node-manager/src/main/java/org/apache/tuscany/sca/node/manager/impl/DomainAssetManagerResourceImpl.java @@ -19,7 +19,6 @@ package org.apache.tuscany.sca.node.manager.impl; -import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -31,25 +30,15 @@ import javax.ws.rs.DefaultValue; import javax.ws.rs.PathParam; import javax.ws.rs.WebApplicationException; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.tuscany.sca.assembly.Binding; 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.binding.rest.RESTBinding; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.host.http.client.HttpClientFactory; 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.ManageableResource; -import org.apache.tuscany.sca.node.manager.ManageableService; +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; @@ -59,8 +48,6 @@ import org.oasisopen.sca.annotation.Scope; public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAssetManagerResource { private static Map nodeMap = new ConcurrentHashMap(); - private HttpClientFactory httpClientFactory; - @Property private int warningTreshold; @@ -87,81 +74,6 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse System.out.println(" - Critical threshold : " + criticalTreshold + " ms"); System.out.println(" - Unavailable threshold : " + unavailableTreshold + " ms"); - NodeExtension node = (NodeExtension) nodeMap.values().iterator().next(); - if(node != null) { - ExtensionPointRegistry extensionPoints = node.getExtensionPointRegistry(); - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - this.httpClientFactory = HttpClientFactory.getInstance(extensionPoints); - } - } - - @Override - public List getResourceStatus(@PathParam("domainURI") @DefaultValue("default") String domainURI) { - if( ! nodeMap.containsKey(domainURI)) { - throw new WebApplicationException(404); - } - - NodeExtension node = nodeMap.get(domainURI); - Composite domainComposite = node.getDomainComposite(); - - List statuses = new ArrayList(); - for(Component component : domainComposite.getComponents()) { - for(Service service : component.getServices()) { - Interface interfaceContract = service.getInterfaceContract().getInterface(); - if(ManageableResource.class.getName().equals(interfaceContract.toString())) { - - //the simple case, the resource is directly exposed with rest binding - Binding binding = service.getBinding(RESTBinding.class); - if(binding == null) { - //the resource is available via some other interface - //(e.g. service implements resource, manageableResource interfaces) - for(Service s : component.getServices()) { - binding = s.getBinding(RESTBinding.class); - if(binding != null) { - break; - } - } - } - - if(binding == null) { - //WARNING that the manageableResource is not exposed via rest binding - } - - if(binding != null) { - - Status status = new Status(); - status.setName(component.getName()); - status.setUri(binding.getURI()); - - try { - Timer t = new Timer(); - status = testResource(status); - status.setExecution(t.elapsed(TimeUnit.MILLISECONDS)); - - if(status.getExecution() < warningTreshold) { - status.setStatus(status.OK); - }else if(status.getExecution() > warningTreshold) { - status.setStatus(Status.WARNING); - }else if(status.getExecution() > criticalTreshold) { - status.setStatus(Status.CRITICAL); - } else { - status.setStatus(Status.UNAVAILABLE); - } - - System.out.println(">>> Execution : " + status.getExecution() + " ms -- " + status.getStatus()); - - } catch (Exception e) { - status.setStatus(Status.UNAVAILABLE); - status.setStatusMessage(e.getMessage()); - } - - statuses.add(status); - } - } - } - - } - return statuses; } @Override @@ -177,7 +89,7 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse for(Component component : domainComposite.getComponents()) { for(Service service : component.getServices()) { Interface interfaceContract = service.getInterfaceContract().getInterface(); - if(ManageableService.class.getName().equals(interfaceContract.toString())) { + if(Manageable.class.getName().equals(interfaceContract.toString())) { Status status = new Status(); status.setName(component.getName()); @@ -185,13 +97,13 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse try { String serviceName = component.getName() + "/" + service.getName(); - ManageableService serviceInstance = node.getService(ManageableService.class, serviceName); + Manageable serviceInstance = node.getService(Manageable.class, serviceName); Timer t = new Timer(); serviceInstance.isAlive(); status.setExecution(t.elapsed(TimeUnit.MILLISECONDS)); if(status.getExecution() < warningTreshold) { - status.setStatus(status.OK); + status.setStatus(Status.OK); }else if(status.getExecution() > warningTreshold) { status.setStatus(Status.WARNING); }else if(status.getExecution() > criticalTreshold) { @@ -212,28 +124,6 @@ public class DomainAssetManagerResourceImpl implements NodeActivator, DomainAsse return statuses; } - - private Status testResource(Status status) throws IOException { - - // Create an HTTP client - HttpClient httpClient = httpClientFactory.createHttpClient(); - - HttpGet request = new HttpGet(status.getUri() + "ping"); - //request.addHeader("Accept","application/json"); - HttpResponse response = httpClient.execute(request); - - if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - throw new IOException("Error invoking service at '" + request.getURI() +"' => " + response.getStatusLine().getReasonPhrase()); - } - - if (httpClient != null) { - httpClient.getConnectionManager().shutdown(); - } - - return status; - } - - class Timer { Date time; long t; -- cgit v1.2.3