Skip to content
This repository has been archived by the owner on Mar 25, 2018. It is now read-only.

#1473: Add JMX support. #1474

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.jclouds.javax.annotation.Nullable;

import com.google.common.collect.Multimap;
import org.jclouds.management.annotations.ManagedAttribute;
import org.jclouds.management.annotations.ManagedType;

/**
* Value type for an HTTP Blob service. Blobs are stored in containers and consist of a
Expand All @@ -30,6 +32,7 @@
*
* @author Adrian Cole
*/
@ManagedType
public interface Blob extends PayloadEnclosing, Comparable<Blob> {
/**
* Allows you to construct blobs without knowing the implementation type
Expand All @@ -45,6 +48,7 @@ public interface Factory {
/**
* @return System and User metadata relevant to this object.
*/
@ManagedAttribute(description = "The metadata related to the blob")
MutableBlobMetadata getMetadata();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
import org.jclouds.javax.annotation.Nullable;

import com.google.inject.ImplementedBy;
import org.jclouds.management.annotations.ManagedAttribute;
import org.jclouds.management.annotations.ManagedType;

/**
* System and user Metadata for the {@link Blob}.
*
* @author Adrian Cole
*/
@ManagedType
@ImplementedBy(BlobMetadataImpl.class)
public interface BlobMetadata extends StorageMetadata {
/**
Expand All @@ -46,7 +49,9 @@ public interface BlobMetadata extends StorageMetadata {
* @return the container holding this blob
*/
@Nullable
@ManagedAttribute(description = "The container holding the blob")
String getContainer();

@ManagedAttribute(description = "The container metadata")
ContentMetadata getContentMetadata();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@
import org.jclouds.javax.annotation.Nullable;

import com.google.inject.ImplementedBy;
import org.jclouds.management.annotations.ManagedAttribute;
import org.jclouds.management.annotations.ManagedType;

/**
* System and user Metadata for the {@link Blob}.
*
* @author Adrian Cole
*/
@ManagedType
@ImplementedBy(MutableBlobMetadataImpl.class)
public interface MutableBlobMetadata extends BlobMetadata, MutableStorageMetadata {
/**
* {@inheritDoc}
*/
@Override
@ManagedAttribute(description = "The content metadata")
MutableContentMetadata getContentMetadata();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import org.jclouds.domain.ResourceMetadata;

import com.google.inject.ImplementedBy;
import org.jclouds.management.annotations.ManagedAttribute;
import org.jclouds.management.annotations.ManagedType;

/**
* Identifies containers, files, etc.
*
* @author Adrian Cole
*/
@ManagedType
@ImplementedBy(StorageMetadataImpl.class)
public interface StorageMetadata extends ResourceMetadata<StorageType> {

Expand All @@ -49,6 +52,7 @@ public interface StorageMetadata extends ResourceMetadata<StorageType> {
* @see org.jclouds.blobstore.attr.ContainerCapability#CONTAINER_METADATA
*/
@Override
@ManagedAttribute(description = "The provider id")
String getProviderId();

/**
Expand All @@ -57,6 +61,7 @@ public interface StorageMetadata extends ResourceMetadata<StorageType> {
*
*/
@Override
@ManagedAttribute(description = "The name of the resource")
String getName();

/**
Expand Down Expand Up @@ -85,6 +90,7 @@ public interface StorageMetadata extends ResourceMetadata<StorageType> {
/**
* Creation date of the resource, possibly null.
*/
@ManagedAttribute(description = "Creation Date")
Date getCreationDate();

/**
Expand All @@ -94,6 +100,7 @@ public interface StorageMetadata extends ResourceMetadata<StorageType> {
* @see org.jclouds.blobstore.attr.ContainerCapability#BLOB_LAST_MODIFIED
* @see org.jclouds.blobstore.attr.ContainerCapability#MILLISECOND_PRECISION
*/
@ManagedAttribute(description = "Last modification date")
Date getLastModified();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@

import static com.google.common.base.Preconditions.checkNotNull;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Singleton;

import org.jclouds.Context;
import org.jclouds.management.annotations.Management;
import org.jclouds.blobstore.AsyncBlobStore;
import org.jclouds.blobstore.BlobMap;
import org.jclouds.blobstore.BlobRequestSigner;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.InputStreamMap;
import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.management.BlobStoreManagement;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.internal.BaseView;
import org.jclouds.location.Provider;
import org.jclouds.rest.RestContext;
import org.jclouds.management.ManagementContext;
import org.jclouds.rest.Utils;

import com.google.common.io.Closeables;
Expand All @@ -52,6 +55,7 @@ public class BlobStoreContextImpl extends BaseView implements BlobStoreContext {
private final ConsistencyModel consistencyModel;
private final Utils utils;
private final BlobRequestSigner blobRequestSigner;
private BlobStoreManagement blobStoreManagement;

@Inject
public BlobStoreContextImpl(@Provider Context backend, @Provider TypeToken<? extends Context> backendType,
Expand All @@ -66,6 +70,15 @@ public BlobStoreContextImpl(@Provider Context backend, @Provider TypeToken<? ext
this.blobStore = checkNotNull(blobStore, "blobStore");
this.utils = checkNotNull(utils, "utils");
this.blobRequestSigner = checkNotNull(blobRequestSigner, "blobRequestSigner");
this.blobStoreManagement = new BlobStoreManagement(this);
}

@PostConstruct
public void init() {
ManagementContext managementContext = unwrap().getManagementContext();
if (managementContext != null) {
managementContext.manage(blobStoreManagement);
}
}

@Override
Expand Down Expand Up @@ -121,6 +134,10 @@ public BlobRequestSigner getSigner() {
@Override
public void close() {
Closeables.closeQuietly(delegate());
ManagementContext managementContext = unwrap().getManagementContext();
if (managementContext != null) {
managementContext.unmanage(blobStoreManagement);
}
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds 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.Iterables;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.domain.Blob;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.domain.Location;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.management.JcloudsManagedBean;
import org.jclouds.management.functions.ToCompositeData;
import org.jclouds.management.functions.ToTabularData;

import javax.management.openmbean.CompositeData;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.TabularData;

public class BlobStoreManagement implements BlobStoreManagementMBean, JcloudsManagedBean {

private final BlobStore blobStore;

private final ToTabularData<Location> locationToTabular = ToTabularData.from(Location.class);
private final ToCompositeData<Blob> blobToComposite = ToCompositeData.from(Blob.class);
private final ToTabularData<StorageMetadata> storageMdToTabular = ToTabularData.from(StorageMetadata.class);
private final ToCompositeData<BlobMetadata> blobMdToComposite = ToCompositeData.from(BlobMetadata.class);


public BlobStoreManagement(BlobStoreContext context) {
this.blobStore = context.getBlobStore();
}


/**
* {@inheritDoc}
*/
@Override
public TabularData listAssignableLocations() throws OpenDataException {
return locationToTabular.apply(blobStore.listAssignableLocations());
}

/**
* {@inheritDoc}
*/
@Override
public TabularData list() throws OpenDataException {
return storageMdToTabular.apply(blobStore.list());
}

/**
* {@inheritDoc}
*/
@Override
public TabularData list(String container) throws OpenDataException {
return storageMdToTabular.apply(blobStore.list(container));
}

/**
* {@inheritDoc}
*/
@Override
public CompositeData blobMetadata(String container, String name) throws OpenDataException {
return blobMdToComposite.apply(blobStore.blobMetadata(container, name));
}

/**
* {@inheritDoc}
*/
@Override
public CompositeData getBlob(String container, String name) throws OpenDataException {
return blobToComposite.apply(blobStore.getBlob(container, name));
}


/**
* {@inheritDoc}
*/
@Override
public boolean containerExists(String container) {
return blobStore.containerExists(container);
}

/**
* {@inheritDoc}
*/
@Override
public boolean createContainerInLocation(@Nullable String locationId, String container) {
Optional<? extends Location> location = Iterables.tryFind(blobStore.listAssignableLocations(), new LocationPredicate(locationId));

if (location.isPresent()) {
return blobStore.createContainerInLocation(location.get(), container);
} else {
return false;
}
}


/**
* {@inheritDoc}
*/
@Override
public void clearContainer(String container) {
blobStore.clearContainer(container);
}


/**
* {@inheritDoc}
*/
@Override
public void deleteContainer(String container) {
blobStore.deleteContainer(container);
}

/**
* {@inheritDoc}
*/
@Override
public boolean directoryExists(String container, String directory) {
return blobStore.directoryExists(container, directory);
}

/**
* {@inheritDoc}
*/
@Override
public void createDirectory(String container, String directory) {
blobStore.createDirectory(container, directory);
}

/**
* {@inheritDoc}
*/
@Override
public void deleteDirectory(String containerName, String name) {
blobStore.deleteDirectory(containerName, name);
}

/**
* {@inheritDoc}
*/
@Override
public boolean blobExists(String container, String name) {
return blobStore.blobExists(container, name);
}

/**
* {@inheritDoc}
*/
@Override
public void removeBlob(String container, String name) {
blobStore.removeBlob(container, name);
}

/**
* {@inheritDoc}
*/
@Override
public long countBlobs(String container) {
return blobStore.countBlobs(container);
}

/**
* Returns the type of the MBean.
*
* @return
*/
@Override
public String getType() {
return "blobstore";
}

/**
* Returns the name of the MBean.
*
* @return
*/
@Override
public String getName() {
return blobStore.getContext().unwrap().getName();
}

private static final class LocationPredicate implements Predicate<Location> {
private final String id;

private LocationPredicate(String id) {
this.id = id;
}

@Override
public boolean apply(@Nullable Location input) {
return input.getId().equals(id);
}
}
}
Loading