org.dasein.cloud.jclouds.openstack.swift.Swift Maven / Gradle / Ivy
/**
* Copyright (C) 2010-2011 enStratusNetworks LLC
*
* ====================================================================
* Licensed 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.dasein.cloud.jclouds.openstack.swift;
import java.util.ArrayList;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.dasein.cloud.AbstractCloud;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.CloudProvider;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.dc.DataCenterServices;
import org.dasein.cloud.jclouds.openstack.swift.storage.SwiftStorage;
import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.concurrent.MoreExecutors;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import com.google.inject.Module;
public class Swift extends AbstractCloud {
static private final Logger logger = Logger.getLogger(Swift.class);
public Swift() { }
public String getCloudName() {
String name = getContext().getCloudName();
return (name == null ? "Generic Swift" : name);
}
public String getProviderName() {
String name = getContext().getProviderName();
return (name == null ? "Generic Swift" : name);
}
public DataCenterServices getDataCenterServices() {
CloudProvider compute = getComputeCloud();
return (compute == null ? new Locales(this) : compute.getDataCenterServices());
}
public SwiftStorage getStorageServices() {
return new SwiftStorage(this);
}
public BlobStoreContext getSwiftContext() throws CloudException {
logger.debug("enter - getSwiftContext()");
try {
Properties overrides = new Properties();
ProviderContext ctx = getContext();
String account = ctx.getAccountNumber() + ":" + new String(ctx.getAccessPublic());
String key = new String(ctx.getAccessPrivate());
ArrayList modules = new ArrayList();
overrides.setProperty("swift.endpoint", ctx.getEndpoint());
overrides.setProperty("swift.apiversion", "1.0");
modules.add(new Log4JLoggingModule());
modules.add(new ExecutorServiceModule(MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()));
return (new BlobStoreContextFactory()).createContext("swift", account, key, modules, overrides);
}
finally {
logger.debug("exit - getSwiftContext()");
}
}
@Override
public String testContext() {
try {
if( !getStorageServices().getBlobStoreSupport().isSubscribed() ) {
return null;
}
return getContext().getAccountNumber();
}
catch( Throwable t ) {
logger.warn("Failed to test Swift connection context: " + t.getMessage());
if( logger.isDebugEnabled() ) {
t.printStackTrace();
}
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy