JCLOUDS-763 Remove jclouds-representations and jclouds-management.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/db7a37ce Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/db7a37ce Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/db7a37ce Branch: refs/heads/master Commit: db7a37ce6458a492046c9616190d9e55ff1f0227 Parents: e3c6a6f Author: Adrian Cole <[email protected]> Authored: Mon Nov 3 20:07:04 2014 -0800 Committer: Adrian Cole <[email protected]> Committed: Tue Nov 4 07:49:37 2014 -0800 ---------------------------------------------------------------------- jclouds-management/README.md | 39 --- jclouds-management/management-blobstore/pom.xml | 64 ----- .../management/BlobStoreManagement.java | 160 ----------- .../management/BlobStoreManagementMBean.java | 24 -- .../management/BlobStoreViewMBeanFactory.java | 48 ---- .../org.jclouds.management.ViewMBeanFactory | 1 - jclouds-management/management-compute/pom.xml | 64 ----- .../management/ComputeServiceManagement.java | 116 -------- .../ComputeServiceManagementMBean.java | 23 -- .../ComputeServiceViewMBeanFactory.java | 48 ---- .../org.jclouds.management.ViewMBeanFactory | 1 - jclouds-management/management-core/pom.xml | 78 ------ .../jclouds/management/JcloudsManagement.java | 127 --------- .../management/JcloudsManagementMBean.java | 72 ----- .../org/jclouds/management/ManagedBean.java | 31 --- .../jclouds/management/ManagementContext.java | 90 ------ .../java/org/jclouds/management/ViewMBean.java | 26 -- .../jclouds/management/ViewMBeanFactories.java | 51 ---- .../jclouds/management/ViewMBeanFactory.java | 40 --- .../management/ViewMBeanFactoryPredicates.java | 50 ---- .../management/config/ManagementLifecycle.java | 118 -------- .../internal/BaseManagementContext.java | 174 ------------ .../management/internal/ManagementUtils.java | 89 ------ .../org/jclouds/management/osgi/Activator.java | 102 ------- .../osgi/ManagementFactoryBundleListener.java | 121 -------- .../osgi/ViewManagementFactoryRegistry.java | 43 --- .../jclouds/management/ComputeMBeanFactory.java | 55 ---- .../jclouds/management/ComputeManagement.java | 34 --- .../management/ComputeManagementMBean.java | 20 -- .../jclouds/management/StorageMBeanFactory.java | 55 ---- .../jclouds/management/StorageManagement.java | 33 --- .../management/StorageManagementMBean.java | 20 -- .../management/ViewMBeanFactoriesTest.java | 61 ---- .../config/ManagementLifecycleTest.java | 61 ---- .../internal/ManagementUtilsTest.java | 94 ------- .../org.jclouds.management.ViewMBeanFactory | 2 - jclouds-management/pom.xml | 42 --- jclouds-representations/README.md | 27 -- jclouds-representations/pom.xml | 41 --- .../representations-codec/pom.xml | 83 ------ .../org/jclouds/blobstore/codec/ToBlob.java | 38 --- .../jclouds/blobstore/codec/ToBlobMetadata.java | 39 --- .../codec/ToContentContentMetadata.java | 37 --- .../blobstore/codec/ToStorageMetadata.java | 37 --- .../java/org/jclouds/codec/ToApiMetadata.java | 64 ----- .../main/java/org/jclouds/codec/ToContext.java | 35 --- .../main/java/org/jclouds/codec/ToLocation.java | 37 --- .../main/java/org/jclouds/codec/ToProvider.java | 86 ------ .../jclouds/compute/codec/ToExecResponse.java | 35 --- .../org/jclouds/compute/codec/ToHardware.java | 46 --- .../java/org/jclouds/compute/codec/ToImage.java | 38 --- .../compute/codec/ToLoginCredentials.java | 36 --- .../jclouds/compute/codec/ToNodeMetadata.java | 40 --- .../compute/codec/ToOperatingSystem.java | 35 --- .../org/jclouds/compute/codec/ToProcessor.java | 34 --- .../org/jclouds/compute/codec/ToVolume.java | 35 --- .../codec/BlobStoreConversionsTest.java | 71 ----- .../org/jclouds/codec/ToApiMetadataTest.java | 52 ---- .../java/org/jclouds/codec/ToContextTest.java | 38 --- .../compute/codec/ComputeConversionsTest.java | 88 ------ .../representations-core/pom.xml | 63 ----- .../jclouds/blobstore/representations/Blob.java | 89 ------ .../blobstore/representations/BlobMetadata.java | 228 --------------- .../blobstore/representations/BlobStore.java | 185 ------------ .../representations/ContentMetadata.java | 163 ----------- .../representations/StorageMetadata.java | 191 ------------- .../compute/representations/ComputeService.java | 122 -------- .../compute/representations/ExecResponse.java | 100 ------- .../compute/representations/Hardware.java | 161 ----------- .../jclouds/compute/representations/Image.java | 172 ------------ .../representations/LoginCredentials.java | 136 --------- .../compute/representations/NodeMetadata.java | 236 ---------------- .../representations/OperatingSystem.java | 141 ---------- .../compute/representations/Processor.java | 88 ------ .../jclouds/compute/representations/Volume.java | 142 ---------- .../jclouds/representations/ApiMetadata.java | 273 ------------------ .../org/jclouds/representations/Context.java | 101 ------- .../org/jclouds/representations/Location.java | 131 --------- .../representations/ProviderMetadata.java | 278 ------------------- .../representations/Representations.java | 31 --- .../representations/StorageMetadataTest.java | 57 ---- .../compute/representations/HardwareTest.java | 63 ----- .../compute/representations/ImageTest.java | 61 ---- .../compute/representations/NodeTest.java | 67 ----- .../representations/ApiMetadataTest.java | 68 ----- .../jclouds/representations/ContextTest.java | 57 ---- .../jclouds/representations/LocationTest.java | 62 ----- .../representations/ProviderMetadataTest.java | 69 ----- .../src/test/resources/ApiMetadata-stub.json | 34 --- .../src/test/resources/Context-stub.json | 5 - .../resources/Location-aws-ec2-eu-west-1a.json | 9 - .../resources/ProviderMetadata-aws-ec2.json | 72 ----- .../resources/blobstore/Blob-aws-s2-test.json | 47 ---- .../blobstore/StorageMetadata-aws-s3-repo.json | 9 - .../resources/compute/Hardware-stub-large.json | 23 -- .../resources/compute/Image-aws-5e7de437.json | 22 -- .../test/resources/compute/Image-stub-1.json | 22 -- .../src/test/resources/compute/Node-stub.json | 19 -- pom.xml | 2 - 99 files changed, 7148 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/README.md ---------------------------------------------------------------------- diff --git a/jclouds-management/README.md b/jclouds-management/README.md deleted file mode 100644 index b7e70ba..0000000 --- a/jclouds-management/README.md +++ /dev/null @@ -1,39 +0,0 @@ -jclouds management -======================= - -This project provides integration of jclouds with JMX. - -Jclouds Managed Beans ---------------------- - -The project provides 3 kind of MBeans: - -* **JcloudsManagementMBean** (single) Exposes Apis, Providers & Contexts. Additionally provides methods for creating Contexts. -* **ComputeServiceManagementMBean** (per context) Exposes all ComputeService operations via JMX. -* **BlobstoreManagementMBean** (per context) Exposes all Blobstore operations via JMX. - - -The ManagementContext ---------------------- - -The ManagementContext is resoposible for keeping track of the MBeanServer, MBean and Contexts LifeCycle. -The default implementation is the BaseManagementContext and it provides method for binding and unbinding an MBeanServer and also jclouds ManagedBean. - -Below is an example that create the ManagementContext and registers the core jclouds management bean. - - ManagementContext managementContext = new BaseManagementContext(); - JcloudsManagementMBean jcloudsManagement = new JcloudsManagement(); - managementContext.manage(jcloudsManagement); - -This will expose via JMX the available Apis, Providers and Contexts. Also it will provide managed methods for creating a Context. -When used inside OSGi the BaseManagementContext is registered as a service, JcloudsManagementMBean will be autoregistered and it will transparently track MBeanServer changes. - -The ManagementLifeCycle module -------------------------------- - -The jclouds management project provides a guice module called ManagementLifecycle. This module can be passed to the ContextBuilder in order to expose mbeans for the created contexts. - - ManagmenetContext managementContext = new BaseManagementContext(); - ContextBuilder.newBuilder(providerOrApi).modules(ImmutableSet.of(new ManagementLifecycle(managementContext)).build(); - - http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-blobstore/pom.xml ---------------------------------------------------------------------- diff --git a/jclouds-management/management-blobstore/pom.xml b/jclouds-management/management-blobstore/pom.xml deleted file mode 100644 index 53624b5..0000000 --- a/jclouds-management/management-blobstore/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>jclouds-management</artifactId> - <groupId>org.apache.jclouds.labs</groupId> - <version>2.0.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.jclouds.labs.management</groupId> - <artifactId>management-blobstore</artifactId> - <packaging>bundle</packaging> - <name>jclouds :: management :: blobstore</name> - - <properties> - <jclouds.osgi.import> - * - </jclouds.osgi.import> - <jclouds.osgi.export> - org.jclouds.management.blobstore*;version="${project.version}";-noimport:=true - </jclouds.osgi.export> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-blobstore</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.jclouds.labs.representations</groupId> - <artifactId>representations-codec</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.jclouds.labs.management</groupId> - <artifactId>management-core</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagement.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagement.java b/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagement.java deleted file mode 100644 index 903f100..0000000 --- a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagement.java +++ /dev/null @@ -1,160 +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.jclouds.blobstore.management; - -import com.google.common.base.Optional; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import org.jclouds.blobstore.BlobStore; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.codec.ToBlob; -import org.jclouds.blobstore.codec.ToBlobMetadata; -import org.jclouds.blobstore.codec.ToStorageMetadata; -import org.jclouds.blobstore.options.ListContainerOptions; -import org.jclouds.codec.ToLocation; -import org.jclouds.management.ViewMBean; -import org.jclouds.representations.Location; -import org.jclouds.blobstore.representations.Blob; -import org.jclouds.blobstore.representations.BlobMetadata; -import org.jclouds.blobstore.representations.StorageMetadata; -import org.jclouds.javax.annotation.Nullable; - -import java.util.Set; - -import static com.google.common.collect.Iterables.transform; -import static com.google.common.collect.Iterables.tryFind; - -public class BlobStoreManagement implements BlobStoreManagementMBean, ViewMBean<BlobStoreContext> { - - private final BlobStore blobStore; - - public BlobStoreManagement(BlobStoreContext context) { - this.blobStore = context.getBlobStore(); - } - - @Override - public Set<Location> listAssignableLocations() { - return ImmutableSet.<Location>builder() - .addAll(transform(blobStore.listAssignableLocations(), ToLocation.INSTANCE)) - .build(); - } - - @Override - public Set<StorageMetadata> list() { - return ImmutableSet.<StorageMetadata>builder() - .addAll(transform(blobStore.list(), ToStorageMetadata.INSTANCE)) - .build(); - } - - @Override - public Set<StorageMetadata> list(String container) { - return ImmutableSet.<StorageMetadata>builder() - .addAll(transform(blobStore.list(container), ToStorageMetadata.INSTANCE)) - .build(); - } - - @Override - public Set<StorageMetadata> list(String container, String directory) { - return ImmutableSet.<StorageMetadata>builder() - .addAll(transform(blobStore.list(container, ListContainerOptions.Builder.inDirectory(directory)), ToStorageMetadata.INSTANCE)) - .build(); - } - - @Override - public BlobMetadata blobMetadata(String container, String name) { - return ToBlobMetadata.INSTANCE.apply(blobStore.blobMetadata(container, name)); - } - - @Override - public Blob getBlob(String container, String name) { - return ToBlob.INSTANCE.apply(blobStore.getBlob(container, name)); - } - - @Override - public boolean containerExists(String container) { - return blobStore.containerExists(container); - } - - @Override - public boolean createContainerInLocation(@Nullable String locationId, String container) { - Optional<? extends org.jclouds.domain.Location> location = tryFind(blobStore.listAssignableLocations(), new LocationPredicate(locationId)); - - if (location.isPresent()) { - return blobStore.createContainerInLocation(location.get(), container); - } else { - return false; - } - } - - @Override - public void clearContainer(String container) { - blobStore.clearContainer(container); - } - - @Override - public void deleteContainer(String container) { - blobStore.deleteContainer(container); - } - - @Override - public boolean directoryExists(String container, String directory) { - return blobStore.directoryExists(container, directory); - } - - @Override - public void createDirectory(String container, String directory) { - blobStore.createDirectory(container, directory); - } - - @Override - public void deleteDirectory(String containerName, String name) { - blobStore.deleteDirectory(containerName, name); - } - - @Override - public boolean blobExists(String container, String name) { - return blobStore.blobExists(container, name); - } - - @Override - public void removeBlob(String container, String name) { - blobStore.removeBlob(container, name); - } - - @Override - public long countBlobs(String container) { - return blobStore.countBlobs(container); - } - - @Override - public String getType() { - return "blobstore"; - } - - private static final class LocationPredicate implements Predicate<org.jclouds.domain.Location> { - private final String id; - - private LocationPredicate(String id) { - this.id = id; - } - - @Override - public boolean apply(@Nullable org.jclouds.domain.Location input) { - return input.getId().equals(id); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagementMBean.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagementMBean.java b/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagementMBean.java deleted file mode 100644 index 7d761b8..0000000 --- a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreManagementMBean.java +++ /dev/null @@ -1,24 +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.jclouds.blobstore.management; - -import org.jclouds.blobstore.representations.BlobStore; - -public interface BlobStoreManagementMBean extends BlobStore { - - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreViewMBeanFactory.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreViewMBeanFactory.java b/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreViewMBeanFactory.java deleted file mode 100644 index c589d61..0000000 --- a/jclouds-management/management-blobstore/src/main/java/org/jclouds/blobstore/management/BlobStoreViewMBeanFactory.java +++ /dev/null @@ -1,48 +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.jclouds.blobstore.management; - -import com.google.common.reflect.TypeToken; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.management.ViewMBean; -import org.jclouds.management.ViewMBeanFactory; - -public class BlobStoreViewMBeanFactory implements ViewMBeanFactory<BlobStoreContext> { - - private static final TypeToken<BlobStoreContext> TYPE = TypeToken.of(BlobStoreContext.class); - - /** - * Creates a {@link org.jclouds.management.ManagedBean} for the Context. - * - * @param view - * @return - */ - @Override - public ViewMBean<BlobStoreContext> create(BlobStoreContext view) { - return new BlobStoreManagement(view); - } - - /** - * Returns the {@link com.google.common.reflect.TypeToken} of the {@link org.jclouds.View}. - * - * @return - */ - @Override - public TypeToken<BlobStoreContext> getViewType() { - return TYPE; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-blobstore/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory ---------------------------------------------------------------------- diff --git a/jclouds-management/management-blobstore/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory b/jclouds-management/management-blobstore/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory deleted file mode 100644 index 6e360fb..0000000 --- a/jclouds-management/management-blobstore/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.blobstore.management.BlobStoreViewMBeanFactory \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-compute/pom.xml ---------------------------------------------------------------------- diff --git a/jclouds-management/management-compute/pom.xml b/jclouds-management/management-compute/pom.xml deleted file mode 100644 index d225536..0000000 --- a/jclouds-management/management-compute/pom.xml +++ /dev/null @@ -1,64 +0,0 @@ -<?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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>jclouds-management</artifactId> - <groupId>org.apache.jclouds.labs</groupId> - <version>2.0.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.jclouds.labs.management</groupId> - <artifactId>management-compute</artifactId> - <packaging>bundle</packaging> - <name>jclouds :: management :: compute</name> - - <properties> - <jclouds.osgi.import> - * - </jclouds.osgi.import> - <jclouds.osgi.export> - org.jclouds.management.compute*;version="${project.version}";-noimport:=true - </jclouds.osgi.export> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.jclouds.labs.representations</groupId> - <artifactId>representations-codec</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.jclouds.labs.management</groupId> - <artifactId>management-core</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagement.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagement.java b/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagement.java deleted file mode 100644 index dd0f8fd..0000000 --- a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagement.java +++ /dev/null @@ -1,116 +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.jclouds.compute.management; - - -import com.google.common.collect.ImmutableSet; -import org.jclouds.codec.ToLocation; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.codec.ToExecResponse; -import org.jclouds.compute.codec.ToHardware; -import org.jclouds.compute.codec.ToImage; -import org.jclouds.compute.codec.ToNodeMetadata; -import org.jclouds.compute.representations.ExecResponse; -import org.jclouds.compute.representations.NodeMetadata; -import org.jclouds.management.ViewMBean; -import org.jclouds.representations.Location; -import org.jclouds.compute.representations.Hardware; -import org.jclouds.compute.representations.Image; - -import java.util.Set; - -import static com.google.common.collect.Iterables.transform; - -public class ComputeServiceManagement implements ComputeServiceManagementMBean, ViewMBean<ComputeServiceContext> { - - private final ComputeService service; - - public ComputeServiceManagement(ComputeServiceContext context) { - this.service = context.getComputeService(); - } - - @Override - public Set<Hardware> listHardwareProfiles() { - return ImmutableSet.<Hardware>builder() - .addAll(transform(service.listHardwareProfiles(), ToHardware.INSTANCE)) - .build(); - } - - @Override - public Set<Image> listImages() { - return ImmutableSet.<Image>builder() - .addAll(transform(service.listImages(), ToImage.INSTANCE)) - .build(); - } - - @Override - public Image getImage(String id) { - return ToImage.INSTANCE.apply(service.getImage(id)); - } - - @Override - public Set<NodeMetadata> listNodes() { - return ImmutableSet.<NodeMetadata>builder() - .addAll(transform( (Set<org.jclouds.compute.domain.NodeMetadata>) service.listNodes(), ToNodeMetadata.INSTANCE)) - .build(); - } - - @Override - public Set<Location> listAssignableLocations() { - return ImmutableSet.<Location>builder() - .addAll(transform(service.listAssignableLocations(), ToLocation.INSTANCE)) - .build(); - } - - @Override - public void resumeNode(String id) { - service.resumeNode(id); - } - - @Override - public void suspendNode(String id) { - service.suspendNode(id); - } - - - @Override - public void destroyNode(String id) { - service.destroyNode(id); - } - - - @Override - public void rebootNode(String id) { - service.destroyNode(id); - } - - @Override - public NodeMetadata getNode(String id) { - return ToNodeMetadata.INSTANCE.apply(service.getNodeMetadata(id)); - } - - @Override - public ExecResponse runScriptOnNode(String id, String runScript) { - return ToExecResponse.INSTANCE.apply(service.runScriptOnNode(id, runScript)); - } - - @Override - public String getType() { - return "compute"; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagementMBean.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagementMBean.java b/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagementMBean.java deleted file mode 100644 index 11ea253..0000000 --- a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceManagementMBean.java +++ /dev/null @@ -1,23 +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.jclouds.compute.management; - -import org.jclouds.compute.representations.ComputeService; - -public interface ComputeServiceManagementMBean extends ComputeService { - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceViewMBeanFactory.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceViewMBeanFactory.java b/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceViewMBeanFactory.java deleted file mode 100644 index bae58d2..0000000 --- a/jclouds-management/management-compute/src/main/java/org/jclouds/compute/management/ComputeServiceViewMBeanFactory.java +++ /dev/null @@ -1,48 +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.jclouds.compute.management; - -import com.google.common.reflect.TypeToken; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.management.ViewMBean; -import org.jclouds.management.ViewMBeanFactory; - - -public class ComputeServiceViewMBeanFactory implements ViewMBeanFactory<ComputeServiceContext> { - - private static final TypeToken<ComputeServiceContext> TYPE = TypeToken.of(ComputeServiceContext.class); - /** - * Creates a {@link org.jclouds.management.ManagedBean} for the Context. - * - * @param context - * @return - */ - @Override - public ViewMBean<ComputeServiceContext> create(ComputeServiceContext context) { - return new ComputeServiceManagement(context); - } - - /** - * Returns the {@link com.google.common.reflect.TypeToken} of the {@link org.jclouds.View}. - * - * @return - */ - @Override - public TypeToken<ComputeServiceContext> getViewType() { - return TYPE; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-compute/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory ---------------------------------------------------------------------- diff --git a/jclouds-management/management-compute/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory b/jclouds-management/management-compute/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory deleted file mode 100644 index 6dde9d4..0000000 --- a/jclouds-management/management-compute/src/main/resources/META-INF/services/org.jclouds.management.ViewMBeanFactory +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.compute.management.ComputeServiceViewMBeanFactory \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/pom.xml ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/pom.xml b/jclouds-management/management-core/pom.xml deleted file mode 100644 index 832937d..0000000 --- a/jclouds-management/management-core/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ -<?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. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <artifactId>jclouds-management</artifactId> - <groupId>org.apache.jclouds.labs</groupId> - <version>2.0.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.jclouds.labs.management</groupId> - <artifactId>management-core</artifactId> - <packaging>bundle</packaging> - <name>jclouds :: management :: core</name> - - <properties> - <jclouds.osgi.import> - * - </jclouds.osgi.import> - <jclouds.osgi.export> - org.jclouds.management*;version="${project.version}";-noimport:=true - </jclouds.osgi.export> - <jclouds.osgi.activator>org.jclouds.management.osgi.Activator</jclouds.osgi.activator> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds.labs.representations</groupId> - <artifactId>representations-codec</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <version>4.2.0</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <version>4.2.0</version> - <scope>provided</scope> - </dependency> - <!-- Testing Dependencies --> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-core</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - <scope>test</scope> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagement.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagement.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagement.java deleted file mode 100644 index 22588cc..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagement.java +++ /dev/null @@ -1,127 +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.jclouds.management; - -import com.google.common.base.Charsets; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableSet; -import org.jclouds.ContextBuilder; -import org.jclouds.apis.Apis; -import org.jclouds.codec.ToApiMetadata; -import org.jclouds.codec.ToContext; -import org.jclouds.codec.ToProvider; -import org.jclouds.util.Closeables2; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.management.config.ManagementLifecycle; -import org.jclouds.management.internal.BaseManagementContext; -import org.jclouds.providers.Providers; -import org.jclouds.representations.ApiMetadata; -import org.jclouds.representations.Context; -import org.jclouds.representations.ProviderMetadata; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Properties; - -import static com.google.common.collect.Iterables.transform; - -/** - * Core Jclouds MBean for displaying available {@link org.jclouds.representations.ApiMetadata}, {@link org.jclouds.representations.ProviderMetadata} and {@link org.jclouds.representations.Context}s. - * Also useful for creating contexts. - */ -public class JcloudsManagement implements JcloudsManagementMBean, ManagedBean { - - private final ManagementContext managementContext; - - public JcloudsManagement() { - this(BaseManagementContext.INSTANCE); - } - - public JcloudsManagement(ManagementContext managementContext) { - this.managementContext = managementContext; - } - - @Override - public Iterable<ApiMetadata> getApis() { - return ImmutableSet.<ApiMetadata>builder() - .addAll(transform(Apis.all(), ToApiMetadata.INSTANCE)) - .build(); - } - - @Override - public ApiMetadata findApiById(String id) { - return ToApiMetadata.INSTANCE.apply(Apis.withId(id)); - } - - @Override - public Iterable<ProviderMetadata> getProviders() { - return ImmutableSet.<ProviderMetadata>builder() - .addAll(transform(Providers.all(), ToProvider.INSTANCE)) - .build(); - } - - @Override - public ProviderMetadata findProviderById(String id) { - return ToProvider.INSTANCE.apply(Providers.withId(id)); - } - - @Override - public Iterable<Context> getContexts() { - return ImmutableSet.<Context>builder() - .addAll(transform(managementContext.listContexts(), ToContext.INSTANCE)) - .build(); - } - - @Override - public Context createContext(String id, String name, String identity, String credential, String endpoint, String overrides) throws IOException { - return ToContext.INSTANCE.apply( - ContextBuilder.newBuilder(id).name(name).credentials(identity, credential).endpoint(endpoint) - .modules(ImmutableSet.of(new ManagementLifecycle(BaseManagementContext.INSTANCE))) - .overrides(stringToProperties(overrides)) - .build() - ); - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "management"; - } - - /** - * Parses the String into a {@link Properties} object. - * The String is expected to separated key from valus using the '=' sign and key/value pairs with a new line. - * @param input - * @return - * @throws IOException - */ - private static Properties stringToProperties(@Nullable String input) throws IOException { - Properties properties = new Properties(); - if (!Strings.isNullOrEmpty(input)) { - ByteArrayInputStream bis = null; - try { - bis = new ByteArrayInputStream(input.getBytes(Charsets.UTF_8)); - properties.load(bis); - } finally { - Closeables2.closeQuietly(bis); - } - } - return properties; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagementMBean.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagementMBean.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagementMBean.java deleted file mode 100644 index 3f6dc9a..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/JcloudsManagementMBean.java +++ /dev/null @@ -1,72 +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.jclouds.management; - - -import org.jclouds.representations.ApiMetadata; -import org.jclouds.representations.Context; -import org.jclouds.representations.ProviderMetadata; - -import java.io.IOException; - - -public interface JcloudsManagementMBean { - - /** - * Lists all available {@link org.jclouds.representations.ApiMetadata}. - * @return - */ - Iterable<ApiMetadata> getApis(); - - /** - * Find {@link org.jclouds.representations.ApiMetadata} by id. - * @return - */ - ApiMetadata findApiById(String id); - - - /** - * Lists all available {@link org.jclouds.representations.ProviderMetadata} - * @return - */ - Iterable<ProviderMetadata> getProviders(); - - - /** - * Find {@link org.jclouds.representations.ProviderMetadata} by id. - * @return - */ - ProviderMetadata findProviderById(String id); - - /** - * Lists all {@link org.jclouds.representations.Context} objects. - * @return - */ - Iterable<Context> getContexts(); - - /** - * Creates a {@link org.jclouds.representations.Context}. - * @param id - * @param name - * @param identity - * @param credential - * @param endpoint - * @param overrides The override properties as a list of new line separated key value pairs. Key/Values are separated by the equals sign. - * @return - */ - Context createContext(String id, String name, String identity, String credential, String endpoint, String overrides) throws IOException; -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagedBean.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagedBean.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagedBean.java deleted file mode 100644 index 0b99840..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagedBean.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.jclouds.management; - -/** - * An interface that describes jclouds managed beans. - * It's used for generating the {@link javax.management.ObjectName}. - */ -public interface ManagedBean { - - /** - * Returns the type of the MBean. - * @return - */ - String getType(); - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagementContext.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagementContext.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagementContext.java deleted file mode 100644 index 442ca79..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ManagementContext.java +++ /dev/null @@ -1,90 +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.jclouds.management; - -import org.jclouds.Context; -import org.jclouds.View; - -import javax.management.MBeanServer; - -/** - * The management context, keeps track of the {@link ManagedBean} objects that have been created. - * It is responsible for exporting beans to the {@link javax.management.MBeanServer}, whenever it becomes available. - * It also keeps track of {@link View}s created, so that they can be accessed via JMX. - */ -public interface ManagementContext { - - /** - * Register a {@link ManagedBean} to the MBeanServer. - * @param mBean The ManagedBean to add to the context. - * @param name The name under which the bean will be exposed. - */ - void manage(ManagedBean mBean, String name); - - /** - * Un-registers a {@link ManagedBean} to the MBeanServer. - * @param mBean The ManagedBean to remove from the context. - * @param name The name under which the bean was exposed. - */ - void unmanage(ManagedBean mBean, String name); - - - /** - * Bind an {@link javax.management.MBeanServer} to the context. - * This is mostly useful for dynamic environments where an {@link javax.management.MBeanServer} may come and go. - * The context should re-register the {@link ManagedBean} objects that have been added to the context. - * @param mBeanServer - */ - void bind(MBeanServer mBeanServer); - - /** - * Unbind an {@link javax.management.MBeanServer} to the context. - * This is mostly useful for dynamic environments where an {@link javax.management.MBeanServer} may come and go. - * The context should unregister the {@link ManagedBean} objects that have been added to the context. - * @param mBeanServer - */ - void unbind(MBeanServer mBeanServer); - - /** - * Register {@link org.jclouds.View}. - * @param view - * @param <V> - */ - <V extends View> void register(V view); - - /** - * Un-register {@link View}. - * @param view - * @param <V> - */ - <V extends View> void unregister(V view); - - /** - * List all registered {@link Context} objects. - * @return - */ - Iterable<? extends Context> listContexts(); - - - /** - * Returns {@link Context} by name. - * @param name - * @param <C> - */ - <C extends Context> C getContext(String name); - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBean.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBean.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBean.java deleted file mode 100644 index 7f89cc6..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBean.java +++ /dev/null @@ -1,26 +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.jclouds.management; - -import org.jclouds.View; - -/** - * A {@link ManagedBean} type for managing {@link View}s. - * @param <V> - */ -public interface ViewMBean<V extends View> extends ManagedBean { -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactories.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactories.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactories.java deleted file mode 100644 index c31f4df..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactories.java +++ /dev/null @@ -1,51 +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.jclouds.management; - -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; -import org.jclouds.management.osgi.ViewManagementFactoryRegistry; - -import java.util.ServiceLoader; - -import static com.google.common.collect.Iterables.filter; - -public class ViewMBeanFactories { - - /** - * Returns the {@link ViewMBeanFactory} located on the classpath via {@link java.util.ServiceLoader}. - * @return all available factories loaded from classpath via {@link java.util.ServiceLoader} - */ - public static Iterable<ViewMBeanFactory> fromServiceLoader() { - return ServiceLoader.load(ViewMBeanFactory.class); - } - - /** - * Returns the {@link ViewMBeanFactory} found via {@link org.jclouds.management.osgi.ViewManagementFactoryRegistry} and {@link java.util.ServiceLoader}. - * @return all available factories. - */ - public static Iterable<ViewMBeanFactory> all() { - return ImmutableSet.<ViewMBeanFactory>builder() - .addAll(fromServiceLoader()) - .addAll(ViewManagementFactoryRegistry.fromRegistry()).build(); - } - - public static Iterable<ViewMBeanFactory> forType(TypeToken viewableAs) { - return filter(all(), ViewMBeanFactoryPredicates.forType(viewableAs)); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactory.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactory.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactory.java deleted file mode 100644 index 3986c10..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactory.java +++ /dev/null @@ -1,40 +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.jclouds.management; - -import com.google.common.reflect.TypeToken; -import org.jclouds.View; - -/** - * A factory for {@ViewManagement}. - * @param <V> - */ -public interface ViewMBeanFactory<V extends View> { - - /** - * Creates a {@link ManagedBean} for the Context. - * @param view - * @return - */ - ViewMBean<V> create(V view); - - /** - * Returns the {@link TypeToken} of the {@link View}. - * @return - */ - TypeToken<V> getViewType(); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactoryPredicates.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactoryPredicates.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactoryPredicates.java deleted file mode 100644 index 2155784..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/ViewMBeanFactoryPredicates.java +++ /dev/null @@ -1,50 +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.jclouds.management; - -import com.google.common.base.Predicate; -import com.google.common.reflect.TypeToken; -import org.jclouds.View; - -import static com.google.common.base.Preconditions.checkNotNull; - -public class ViewMBeanFactoryPredicates { - - public static <V extends View> Predicate<ViewMBeanFactory<V>> forType(final TypeToken<V> type) { - checkNotNull(type, "type"); - return new ViewMBeanFactoryForType<V>(type); - } - - private static class ViewMBeanFactoryForType<V extends View> implements Predicate<ViewMBeanFactory<V>> { - - private final TypeToken<V> type; - - private ViewMBeanFactoryForType(TypeToken<V> type) { - this.type = type; - } - - @Override - public boolean apply(ViewMBeanFactory factory) { - return factory.getViewType().isAssignableFrom(type); - } - - @Override - public String toString() { - return "forType(" + type + ")"; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/config/ManagementLifecycle.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/config/ManagementLifecycle.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/config/ManagementLifecycle.java deleted file mode 100644 index f27d800..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/config/ManagementLifecycle.java +++ /dev/null @@ -1,118 +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.jclouds.management.config; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.reflect.TypeToken; -import com.google.inject.AbstractModule; -import com.google.inject.TypeLiteral; -import com.google.inject.matcher.AbstractMatcher; -import com.google.inject.matcher.Matcher; -import com.google.inject.matcher.Matchers; -import com.google.inject.spi.InjectionListener; -import com.google.inject.spi.TypeEncounter; -import com.google.inject.spi.TypeListener; -import org.jclouds.View; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.lifecycle.Closer; -import org.jclouds.management.ManagementContext; -import org.jclouds.management.ViewMBean; -import org.jclouds.management.ViewMBeanFactories; -import org.jclouds.management.ViewMBeanFactory; - -import java.io.Closeable; -import java.io.IOException; - -/** - * A {@link com.google.inject.Module} for managing the lifecycle of {@link org.jclouds.management.ViewMBean} beans. - * The goal of this module is to create {@link org.jclouds.management.ViewMBean} beans that correspond to each {@link View} created/destroyed - * and register/un-register them to the {@link ManagementContext}. - */ -public class ManagementLifecycle extends AbstractModule { - - private final ManagementContext managementContext; - - public ManagementLifecycle(ManagementContext context) { - this.managementContext = context; - } - - @Override - protected void configure() { - bindListener(subClassOf(View.class), new TypeListener() { - @Override - public <I> void hear(final TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) { - typeEncounter.register(new InjectionListener<I>() { - @Override - public void afterInjection(Object object) { - final View view = (View) object; - final Iterable<ViewMBean> viewMamanagementBeans = viewManagementOf(view); - final Closer closer = view.unwrap().utils().injector().getInstance(Closer.class); - //We get the name from the view and not from the view management object to avoid proxy issues. - final String name = view.unwrap().getName(); - managementContext.register(view); - - //Manage the created management view objects to the context. - for (ViewMBean viewMBean : viewMamanagementBeans) { - managementContext.manage(viewMBean, name); - } - - //Add the the management view objects to the Closer, so that they are unregistered on close. - closer.addToClose(new Closeable() { - @Override - public void close() throws IOException { - for (ViewMBean viewMBean : viewMamanagementBeans) { - managementContext.unmanage(viewMBean, name); - } - managementContext.unregister(view); - } - }); - } - }); - } - }); - } - - /** - * Returns an {@link Iterable} of {@link org.jclouds.management.ViewMBean} for the specified {@link View}. - * @param view - * @return - */ - private static Iterable<ViewMBean> viewManagementOf(final View view) { - TypeToken type = TypeToken.of(view.getClass()); - return Iterables.transform(ViewMBeanFactories.forType(type), new Function<ViewMBeanFactory, ViewMBean>() { - @Override - public ViewMBean apply(@Nullable ViewMBeanFactory factory) { - return factory.create(view); - } - }); - } - - /** - * Creates a {@link TypeLiteral} {@link Matcher} for matching subclasses. - * This is for use in bindListener. - * @param clazz - * @return - */ - private static Matcher<TypeLiteral> subClassOf(final Class<?> clazz) { - return new AbstractMatcher<TypeLiteral>() { - public boolean matches (TypeLiteral typeLiteral){ - return Matchers.subclassesOf(clazz).matches(typeLiteral.getRawType()); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/BaseManagementContext.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/BaseManagementContext.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/BaseManagementContext.java deleted file mode 100644 index 3676e8a..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/BaseManagementContext.java +++ /dev/null @@ -1,174 +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.jclouds.management.internal; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import org.jclouds.Context; -import org.jclouds.View; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.management.ManagedBean; -import org.jclouds.management.ManagementContext; - -import javax.management.MBeanServer; -import java.lang.management.ManagementFactory; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkNotNull; - -public enum BaseManagementContext implements ManagementContext { - - INSTANCE; - - private final Map<String, View> views = Maps.newHashMap(); - private final Map<Key, ManagedBean> mbeans = Maps.newHashMap(); - - //The MBeanServer can be bind/unbind (especially inside OSGi) so its not always available. - //Thus is represented as Optional. - private Optional<MBeanServer> mBeanServer = Optional.of(ManagementFactory.getPlatformMBeanServer()); - - /** - * {@inheritDoc} - */ - @Override - public synchronized void manage(ManagedBean mBean, String name) { - if (mBeanServer.isPresent()) { - ManagementUtils.register(mBeanServer.get(), mBean, mBean.getType(), name); - } - mbeans.put(new Key(mBean, name), mBean); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void unmanage(ManagedBean mBean, String name) { - if (mBeanServer.isPresent()) { - ManagementUtils.unregister(mBeanServer.get(), mBean.getType(), name); - } - mbeans.remove(new Key(mBean, name)); - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void bind(MBeanServer server) { - this.mBeanServer = Optional.of(server); - for (Map.Entry<Key, ManagedBean> entry : mbeans.entrySet()) { - String name = entry.getKey().getName(); - ManagedBean mBean = entry.getValue(); - ManagementUtils.register(server, mBean, mBean.getType(), name); - } - } - - /** - * {@inheritDoc} - */ - @Override - public synchronized void unbind(MBeanServer server) { - for (Map.Entry<Key, ManagedBean> entry : mbeans.entrySet()) { - String name = entry.getKey().getName(); - ManagedBean mBean = entry.getValue(); - ManagementUtils.unregister(server, mBean.getType(), name); - } - this.mBeanServer = Optional.absent(); - } - - - /** - * {@inheritDoc} - */ - @Override - public <V extends View> void register(V view) { - views.put(view.unwrap().getName(), view); - } - - /** - * {@inheritDoc} - */ - @Override - public <V extends View> void unregister(V view) { - views.remove(view.unwrap().getName()); - } - - /** - * {@inheritDoc} - */ - @Override - public Iterable<? extends Context> listContexts() { - return Iterables.transform(views.values(), new Function<View, Context>() { - @Override - public Context apply(@Nullable View input) { - return input.unwrap(); - } - }); - } - - /** - * {@inheritDoc} - */ - @Override - public Context getContext(String name) { - return views.get(name).unwrap(); - } - - private class Key { - - private final String type; - private final String name; - - public Key(String type, String name) { - this.type = checkNotNull(type, "type"); - this.name = checkNotNull(name, "name"); - } - - public Key(ManagedBean mbean, String name) { - this(checkNotNull(mbean, "mbean").getType(), name); - } - - public String getType() { - return type; - } - - public String getName() { - return name; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Key key = (Key) o; - - if (name != null ? !name.equals(key.name) : key.name != null) return false; - if (type != null ? !type.equals(key.type) : key.type != null) return false; - - return true; - } - - @Override - public int hashCode() { - int result = type != null ? type.hashCode() : 0; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/ManagementUtils.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/ManagementUtils.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/ManagementUtils.java deleted file mode 100644 index f1ff7f3..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/internal/ManagementUtils.java +++ /dev/null @@ -1,89 +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.jclouds.management.internal; - -import com.google.common.base.Throwables; -import org.jclouds.JcloudsVersion; - -import javax.management.MBeanRegistrationException; -import javax.management.MBeanServer; -import javax.management.MalformedObjectNameException; -import javax.management.ObjectName; -import javax.management.OperationsException; - -public final class ManagementUtils { - - private static final JcloudsVersion VERSION = JcloudsVersion.get(); - private static final String OBJECT_NAME_FORMAT = "org.jclouds:type=%s,name=%s,version=%d.%d"; - - private ManagementUtils() { - //Utility Class - } - - /** - * Registers a managed object to the mbean server. - * - * @param mBeanServer - * @param mbean - * @param type - * @param name - */ - public static void register(MBeanServer mBeanServer, Object mbean, String type, String name) { - try { - ObjectName objectName = objectNameFor(type, name); - if (!mBeanServer.isRegistered(objectName)) { - mBeanServer.registerMBean(mbean, objectName); - } - } catch (OperationsException e) { - Throwables.propagate(e); - } catch (MBeanRegistrationException e) { - Throwables.propagate(e); - } - } - - /** - * Un-registers a managed object to the mbean server. - * - * @param mBeanServer - * @param type - * @param name - */ - public static void unregister(MBeanServer mBeanServer, String type, String name) { - try { - ObjectName objectName = objectNameFor(type, name); - if (mBeanServer.isRegistered(objectName)) { - mBeanServer.unregisterMBean(objectName); - } - } catch (OperationsException e) { - Throwables.propagate(e); - } catch (MBeanRegistrationException e) { - Throwables.propagate(e); - } - } - - - /** - * Creates a jclouds {@link javax.management.ObjectName} for the mbean type. - * - * @param type - * @return - * @throws javax.management.MalformedObjectNameException - */ - public static ObjectName objectNameFor(String type, String name) throws MalformedObjectNameException { - return new ObjectName(String.format(OBJECT_NAME_FORMAT, type, name, VERSION.majorVersion, VERSION.minorVersion)); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/Activator.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/Activator.java deleted file mode 100644 index abe5532..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/Activator.java +++ /dev/null @@ -1,102 +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.jclouds.management.osgi; - -import org.jclouds.management.JcloudsManagement; -import org.jclouds.management.internal.BaseManagementContext; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.util.tracker.ServiceTracker; - -import javax.management.MBeanServer; - -public class Activator implements BundleActivator { - - private ServiceTracker mbeanServerTracker = null; - private ManagementFactoryBundleListener bundleListener = new ManagementFactoryBundleListener(); - private final JcloudsManagement jcloudsManagement = new JcloudsManagement(); - - /** - * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start - * this bundle. This method can be used to register services or to allocate any resources that this bundle needs. - * <p/> - * <p/> - * This method must complete and return to its caller in a timely manner. - * - * @param context - * The execution context of the bundle being started. - * @throws Exception - * If this method throws an exception, this bundle is marked as stopped and the Framework will remove this - * bundle's listeners, unregister all services registered by this bundle, and release all services used by - * this bundle. - */ - @Override - public void start(BundleContext context) throws Exception { - bundleListener.start(context); - mbeanServerTracker = new ServiceTracker(context, MBeanServer.class.getName(), null) { - - @Override - public Object addingService(ServiceReference reference) { - Object obj = super.addingService(reference); - if (MBeanServer.class.isAssignableFrom(obj.getClass())) { - BaseManagementContext.INSTANCE.bind((MBeanServer) obj); - BaseManagementContext.INSTANCE.manage(jcloudsManagement, "core"); - } - return obj; - } - - @Override - public void modifiedService(ServiceReference reference, Object service) { - super.modifiedService(reference, service); - } - - @Override - public void removedService(ServiceReference reference, Object service) { - if (MBeanServer.class.isAssignableFrom(service.getClass())) { - BaseManagementContext.INSTANCE.unbind((MBeanServer) service); - } - super.removedService(reference, service); - } - }; - mbeanServerTracker.open(); - } - - /** - * Called when this bundle is stopped so the Framework can perform the bundle-specific activities necessary to stop - * the bundle. In general, this method should undo the work that the <code>BundleActivator.start</code> method - * started. There should be no active threads that were started by this bundle when this bundle returns. A stopped - * bundle must not call any Framework objects. - * <p/> - * <p/> - * This method must complete and return to its caller in a timely manner. - * - * @param context - * The execution context of the bundle being stopped. - * @throws Exception - * If this method throws an exception, the bundle is still marked as stopped, and the Framework will - * remove the bundle's listeners, unregister all services registered by the bundle, and release all - * services used by the bundle. - */ - @Override - public void stop(BundleContext context) throws Exception { - bundleListener.stop(context); - if (mbeanServerTracker != null) { - mbeanServerTracker.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ManagementFactoryBundleListener.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ManagementFactoryBundleListener.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ManagementFactoryBundleListener.java deleted file mode 100644 index 2a4edd0..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ManagementFactoryBundleListener.java +++ /dev/null @@ -1,121 +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.jclouds.management.osgi; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import org.jclouds.management.ViewMBeanFactory; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.BundleListener; - -import static org.jclouds.osgi.Bundles.instantiateAvailableClasses; -import static org.jclouds.osgi.Bundles.stringsForResourceInBundle; -import static org.osgi.framework.BundleEvent.STARTED; -import static org.osgi.framework.BundleEvent.STOPPING; -import static org.osgi.framework.BundleEvent.STOPPED; - -/** - * A {@link org.osgi.framework.BundleListener} that listens for {@link org.osgi.framework.BundleEvent} and searches for - * {@link org.jclouds.providers.ProviderMetadata} and {@link org.jclouds.apis.ApiMetadata} in newly installed Bundles. - * This is used as a workaround for OSGi environments where the ServiceLoader cannot cross bundle boundaries. - */ -public class ManagementFactoryBundleListener implements BundleListener { - - private final Multimap<Long, ViewMBeanFactory> managedViewFactoryMap = ArrayListMultimap.create(); - - /** - * Starts the listener. Checks the bundles that are already active and registers {@link org.jclouds.providers.ProviderMetadata} and - * {@link org.jclouds.apis.ApiMetadata} found. Registers the itself as a {@link org.osgi.framework.BundleListener}. - * - * @param bundleContext - */ - public synchronized void start(BundleContext bundleContext) { - bundleContext.addBundleListener(this); - for (Bundle bundle : bundleContext.getBundles()) { - if (bundle.getState() == Bundle.ACTIVE) { - addBundle(bundle); - } - } - bundleContext.addBundleListener(this); - } - - /** - * Stops the listener. Removes itself from the {@link org.osgi.framework.BundleListener}s. Clears metadata maps and listeners lists. - * - * @param bundleContext - */ - public void stop(BundleContext bundleContext) { - bundleContext.removeBundleListener(this); - managedViewFactoryMap.clear(); - } - - @Override - public synchronized void bundleChanged(BundleEvent event) { - switch (event.getType()) { - case STARTED: - addBundle(event.getBundle()); - break; - case STOPPING: - case STOPPED: - removeBundle(event.getBundle()); - break; - } - } - - /** - * Searches for {@link org.jclouds.providers.ProviderMetadata} and {@link org.jclouds.apis.ApiMetadata} inside the {@link org.osgi.framework.Bundle}. If metadata are found - * they are registered in the {@link org.jclouds.osgi.ProviderRegistry} and {@link org.jclouds.osgi.ApiRegistry}. Also the {@link org.jclouds.osgi.ProviderListener} and - * {@link org.jclouds.osgi.ApiListener} are notified. - * - * @param bundle - */ - private synchronized void addBundle(Bundle bundle) { - for (ViewMBeanFactory viewMBeanFactory : listManagedViewFactories(bundle)) { - if (viewMBeanFactory != null) { - ViewManagementFactoryRegistry.registerFactory(viewMBeanFactory); - managedViewFactoryMap.put(bundle.getBundleId(), viewMBeanFactory); - } - } - } - - /** - * Searches for {@link org.jclouds.providers.ProviderMetadata} and {@link org.jclouds.apis.ApiMetadata} registered under the {@link org.osgi.framework.Bundle} id. If metadata - * are found they are removed the {@link org.jclouds.osgi.ProviderRegistry} and {@link org.jclouds.osgi.ApiRegistry}. Also the {@link org.jclouds.osgi.ProviderListener} - * and {@link org.jclouds.osgi.ApiListener} are notified. - * - * @param bundle - */ - private synchronized void removeBundle(Bundle bundle) { - for (ViewMBeanFactory viewMBeanFactory : managedViewFactoryMap.removeAll(bundle.getBundleId())) { - ViewManagementFactoryRegistry.registerFactory(viewMBeanFactory); - } - - } - - /** - * Creates an instance of {@link org.jclouds.management.ViewMBeanFactory} from the {@link org.osgi.framework.Bundle}. - * - * @param bundle - * @return - */ - public Iterable<ViewMBeanFactory> listManagedViewFactories(Bundle bundle) { - Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/" + ViewMBeanFactory.class.getName(), bundle); - return instantiateAvailableClasses(bundle, classNames, ViewMBeanFactory.class); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/db7a37ce/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ViewManagementFactoryRegistry.java ---------------------------------------------------------------------- diff --git a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ViewManagementFactoryRegistry.java b/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ViewManagementFactoryRegistry.java deleted file mode 100644 index fec399b..0000000 --- a/jclouds-management/management-core/src/main/java/org/jclouds/management/osgi/ViewManagementFactoryRegistry.java +++ /dev/null @@ -1,43 +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.jclouds.management.osgi; - -import com.google.common.collect.Sets; -import org.jclouds.management.ViewMBeanFactory; - -import java.util.Set; - -public class ViewManagementFactoryRegistry { - - private static final Set<ViewMBeanFactory> factories = Sets.newHashSet(); - - public static void registerFactory(ViewMBeanFactory factory) { - factories.add(factory); - } - - public static void unRegisterFactory(ViewMBeanFactory factory) { - factories.remove(factory); - } - - public static Iterable<ViewMBeanFactory> fromRegistry() { - return factories; - } - - public static void clear() { - factories.clear(); - } -}
