mirror of https://github.com/apache/jclouds.git
JCLOUDS-25. Remove oprhaned sandbox-* from repo
This commit is contained in:
parent
c63b932962
commit
23d9d901d3
|
@ -1,92 +0,0 @@
|
||||||
====
|
|
||||||
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.
|
|
||||||
====
|
|
||||||
|
|
||||||
The libvirt library is used to interface with different virtualization technologies (http://libvirt.org/)
|
|
||||||
|
|
||||||
libvirt supports:
|
|
||||||
The Xen hypervisor on Linux and Solaris hosts.
|
|
||||||
The QEMU emulator
|
|
||||||
The KVM Linux hypervisor
|
|
||||||
The LXC Linux container system
|
|
||||||
The OpenVZ Linux container system
|
|
||||||
The User Mode Linux paravirtualized kernel
|
|
||||||
The VirtualBox hypervisor
|
|
||||||
The VMware ESX and GSX hypervisors
|
|
||||||
Storage on IDE/SCSI/USB disks, FibreChannel, LVM, iSCSI, NFS and filesystems
|
|
||||||
|
|
||||||
Getting Started Guide for jclouds-libvirt
|
|
||||||
|
|
||||||
install libvirt on your os
|
|
||||||
* if os/x, see http://github.com/justinclift/libvirt
|
|
||||||
* if you are using Linux, let's suppose you want to use KVM:
|
|
||||||
- install libvirt and KVM (http://www.linux-kvm.org/page/Main_Page).
|
|
||||||
|
|
||||||
Remember to run
|
|
||||||
egrep '(vmx|svm)' /proc/cpuinfo
|
|
||||||
If nothing is printed, it means that your cpu does not support hardware virtualization.
|
|
||||||
|
|
||||||
Verify Installation
|
|
||||||
$ virsh -c qemu:///system list
|
|
||||||
Id Name State
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
(for Ubuntu users: look also at this good turorial https://help.ubuntu.com/community/KVM)
|
|
||||||
|
|
||||||
Create your first guest
|
|
||||||
- download, for example, an ubuntu 10.04 LTS ISO
|
|
||||||
- create a libvirt domain by using:
|
|
||||||
virt-manager: a GUI tool at http://virt-manager.et.redhat.com/
|
|
||||||
virt-install, a python script developed by Red Hat (sudo apt-get install python-virtinst)
|
|
||||||
ubuntu-vm-builder, developed by Canonical. (sudo apt-get install ubuntu-vm-builder)
|
|
||||||
NB: use Javascript tool that generates the parameters for ubuntu-vm-builder: http://people.ubuntu.com/~kirkland/ubuntu-vm-builder.html
|
|
||||||
|
|
||||||
Now that you have a libvirt domain, your workstation is ready to use jclouds-libvirt.
|
|
||||||
You can now download jclouds-libvirt and give a try by running
|
|
||||||
|
|
||||||
ComputeServiceContext context = null;
|
|
||||||
try {
|
|
||||||
context = new ComputeServiceContextFactory()
|
|
||||||
.createContext(new StandaloneComputeServiceContextSpec<Domain, Domain, Image, Datacenter>("libvirt",
|
|
||||||
endpoint, apiversion, identity, credential, new LibvirtComputeServiceContextModule(), ImmutableSet
|
|
||||||
.<Module> of()));
|
|
||||||
|
|
||||||
Template defaultTemplate = context.getComputeService().templateBuilder()
|
|
||||||
.hardwareId("c7ff2039-a9f1-a659-7f91-e0f82f59d52e").imageId("1").build();
|
|
||||||
|
|
||||||
|
|
||||||
context.getComputeService().runNodesWithTag(domainName, 1, defaultTemplate);
|
|
||||||
|
|
||||||
} catch (RunNodesException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (context != null)
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
where identity=your_name, endpoint=qemu:///system
|
|
||||||
and domainName equals to the name chosen during the creation of libvirt domain
|
|
||||||
|
|
||||||
NB: apiversion, credential can be null
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
runNodesWithTag: when ask for more than 1 node, cloning step fails cause of concurrent access to the originale virtual disk to be cloned.
|
|
|
@ -1,147 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<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/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-project</artifactId>
|
|
||||||
<version>1.7.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../../project/pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<groupId>org.jclouds.api</groupId>
|
|
||||||
<artifactId>libvirt</artifactId>
|
|
||||||
<name>jclouds example components for a libvirt provider</name>
|
|
||||||
<packaging>bundle</packaging>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<!-- when instances are hung, open a ticket and add here -->
|
|
||||||
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
|
|
||||||
<test.libvirt.endpoint>test:///default</test.libvirt.endpoint>
|
|
||||||
<test.libvirt.api-version>1.0</test.libvirt.api-version>
|
|
||||||
<test.libvirt.build-version></test.libvirt.build-version>
|
|
||||||
<test.libvirt.identity>FIXME</test.libvirt.identity>
|
|
||||||
<test.libvirt.credential>FIXME</test.libvirt.credential>
|
|
||||||
<test.libvirt.image-id></test.libvirt.image-id>
|
|
||||||
|
|
||||||
<jclouds.osgi.export>org.jclouds.libvirt*;version="${project.version}"</jclouds.osgi.export>
|
|
||||||
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.libvirt</groupId>
|
|
||||||
<artifactId>libvirt</artifactId>
|
|
||||||
<version>0.4.6</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>2.4</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sun.jna</groupId>
|
|
||||||
<artifactId>jna</artifactId>
|
|
||||||
<version>3.0.9</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.jamesmurty.utils</groupId>
|
|
||||||
<artifactId>java-xmlbuilder</artifactId>
|
|
||||||
<version>0.3</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-compute</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-compute</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds.driver</groupId>
|
|
||||||
<artifactId>jclouds-log4j</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds.driver</groupId>
|
|
||||||
<artifactId>jclouds-jsch</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.jcraft</groupId>
|
|
||||||
<artifactId>jsch</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>live</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>integration</id>
|
|
||||||
<phase>integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<test.libvirt.endpoint>${test.libvirt.endpoint}</test.libvirt.endpoint>
|
|
||||||
<test.libvirt.api-version>${test.libvirt.api-version}</test.libvirt.api-version>
|
|
||||||
<test.libvirt.build-version>${test.libvirt.build-version}</test.libvirt.build-version>
|
|
||||||
<test.libvirt.identity>${test.libvirt.identity}</test.libvirt.identity>
|
|
||||||
<test.libvirt.credential>${test.libvirt.credential}</test.libvirt.credential>
|
|
||||||
<test.libvirt.image-id>${test.libvirt.image-id}</test.libvirt.image-id>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,55 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt;
|
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This would be replaced with the real java object related to the underlying image
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class Image {
|
|
||||||
|
|
||||||
public int id;
|
|
||||||
public String name;
|
|
||||||
|
|
||||||
public Image(int id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(id, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object that) {
|
|
||||||
if (that == null)
|
|
||||||
return false;
|
|
||||||
return Objects.equal(this.toString(), that.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return Objects.toStringHelper(this).add("id", id).add("name", name).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration properties and constants used in libvirt local connections.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public interface LibvirtConstants {
|
|
||||||
public static final String PROPERTY_LIBVIRT_DOMAIN_DIR = "jclouds.libvirt.domain.dir";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//public static final String PROPERTY_AUTH_TAG = "jclouds.aws.auth.tag";
|
|
||||||
//public static final String PROPERTY_HEADER_TAG = "jclouds.aws.header.tag";
|
|
|
@ -1,121 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.collect.Memoized;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.ImageExtension;
|
|
||||||
import org.jclouds.compute.callables.RunScriptOnNode;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
|
||||||
import org.jclouds.compute.internal.BaseComputeService;
|
|
||||||
import org.jclouds.compute.internal.PersistNodeCredentials;
|
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
|
|
||||||
import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet;
|
|
||||||
import org.jclouds.compute.strategy.DestroyNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
|
|
||||||
import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
|
|
||||||
import org.jclouds.compute.strategy.ListNodesStrategy;
|
|
||||||
import org.jclouds.compute.strategy.RebootNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.ResumeNodeStrategy;
|
|
||||||
import org.jclouds.compute.strategy.SuspendNodeStrategy;
|
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.scriptbuilder.functions.InitAdminAccess;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
import org.libvirt.StorageVol;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author andrea turli
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LibvirtComputeService extends BaseComputeService {
|
|
||||||
|
|
||||||
private final Connect client;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
protected LibvirtComputeService(ComputeServiceContext context, Map<String, Credentials> credentialStore,
|
|
||||||
@Memoized Supplier<Set<? extends Image>> images,
|
|
||||||
@Memoized Supplier<Set<? extends Hardware>> hardwareProfiles,
|
|
||||||
@Memoized Supplier<Set<? extends Location>> locations, ListNodesStrategy listNodesStrategy,
|
|
||||||
GetNodeMetadataStrategy getNodeMetadataStrategy,
|
|
||||||
CreateNodesInGroupThenAddToSet runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
|
|
||||||
DestroyNodeStrategy destroyNodeStrategy, ResumeNodeStrategy resumeNodeStrategy,
|
|
||||||
SuspendNodeStrategy suspendNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
|
|
||||||
Provider<TemplateOptions> templateOptionsProvider,
|
|
||||||
@Named("NODE_RUNNING") Predicate<NodeMetadata> nodeRunning,
|
|
||||||
@Named("NODE_TERMINATED") Predicate<NodeMetadata> nodeTerminated,
|
|
||||||
@Named("NODE_SUSPENDED") Predicate<NodeMetadata> nodeSuspended,
|
|
||||||
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitAdminAccess initAdminAccess,
|
|
||||||
RunScriptOnNode.Factory runScriptOnNodeFactory, PersistNodeCredentials persistNodeCredentials,
|
|
||||||
Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, Connect client,
|
|
||||||
Optional<ImageExtension> imageExtension) {
|
|
||||||
super(context, credentialStore, images, hardwareProfiles, locations, listNodesStrategy, getNodeMetadataStrategy,
|
|
||||||
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
|
|
||||||
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,
|
|
||||||
nodeSuspended, initScriptRunnerFactory, initAdminAccess, runScriptOnNodeFactory, persistNodeCredentials,
|
|
||||||
timeouts, executor, imageExtension);
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cleanUpIncidentalResourcesOfDeadNodes(Set<? extends NodeMetadata> deadNodes) {
|
|
||||||
// TODO Was previously commented out in overridden destroyNode; refactored to here but left commented out
|
|
||||||
// for (NodeMetadata deadNode : deadNodes) {
|
|
||||||
// eliminateDomain(deadNode.getId());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void eliminateDomain(String id) {
|
|
||||||
try {
|
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(client.domainLookupByUUIDString(id)
|
|
||||||
.getXMLDesc(0))));
|
|
||||||
String diskFileName = builder.xpathFind("//devices/disk[@device='disk']/source").getElement().getAttribute(
|
|
||||||
"file");
|
|
||||||
StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
|
|
||||||
storageVol.delete(0);
|
|
||||||
client.domainLookupByUUIDString(id).undefine();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import static org.jclouds.libvirt.LibvirtConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
|
|
||||||
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class LibvirtComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<Connect> {
|
|
||||||
|
|
||||||
public LibvirtComputeServiceContextBuilder(Properties props) {
|
|
||||||
super(Connect.class, props);
|
|
||||||
|
|
||||||
if (!properties.containsKey(PROPERTY_LIBVIRT_DOMAIN_DIR))
|
|
||||||
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addContextModule(List<Module> modules) {
|
|
||||||
modules.add(new LibvirtComputeServiceContextModule());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
|
||||||
import org.jclouds.compute.ComputeService;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class LibvirtComputeServiceContextSpec extends RestContextSpec<ComputeService, ComputeService> {
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public LibvirtComputeServiceContextSpec(String endpoint, String identity, String credential, Iterable<Module> modules) {
|
|
||||||
super("libvirt", endpoint, "1", "", identity, credential, ComputeService.class, ComputeService.class,
|
|
||||||
PropertiesBuilder.class, (Class) LibvirtComputeServiceContextBuilder.class, modules);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibvirtComputeServiceContextSpec(String endpoint, String identity, String credential) {
|
|
||||||
this(endpoint, identity, credential, ImmutableSet.<Module> of());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
|
||||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
|
||||||
import static org.jclouds.libvirt.LibvirtConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds properties used in Libvirt Clients
|
|
||||||
*
|
|
||||||
* @author Andrea Turli
|
|
||||||
*/
|
|
||||||
public class LibvirtPropertiesBuilder extends PropertiesBuilder {
|
|
||||||
@Override
|
|
||||||
protected Properties defaultProperties() {
|
|
||||||
Properties properties = super.defaultProperties();
|
|
||||||
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
|
|
||||||
|
|
||||||
/*
|
|
||||||
properties.setProperty(PROPERTY_AUTH_TAG, "AWS");
|
|
||||||
properties.setProperty(PROPERTY_HEADER_TAG, "amz");
|
|
||||||
properties.setProperty(PROPERTY_ENDPOINT, "https://ec2.us-east-1.amazonaws.com");
|
|
||||||
properties.setProperty(PROPERTY_API_VERSION, EC2AsyncClient.VERSION);
|
|
||||||
properties.setProperty(PROPERTY_ELB_ENDPOINT, "https://elasticloadbalancing.us-east-1.amazonaws.com");
|
|
||||||
// amazon, alestic, canonical, and rightscale
|
|
||||||
properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "137112412989,063491364108,099720109477,411009282317");
|
|
||||||
// amis that work with the cluster instances
|
|
||||||
properties.setProperty(PROPERTY_EC2_CC_AMIs, "us-east-1/ami-7ea24a17");
|
|
||||||
*/
|
|
||||||
|
|
||||||
// sometimes, like in ec2, stop takes a very long time, perhaps
|
|
||||||
// due to volume management. one example spent 2 minutes moving
|
|
||||||
// from stopping->stopped state on an ec2 micro
|
|
||||||
properties.setProperty(PROPERTY_TIMEOUT_NODE_SUSPENDED, 120 * 1000 + "");
|
|
||||||
// auth fail sometimes happens in EC2, as the rc.local script that injects the
|
|
||||||
// authorized key executes after ssh has started
|
|
||||||
properties.setProperty("jclouds.ssh.max_retries", "7");
|
|
||||||
properties.setProperty("jclouds.ssh.retryable_messages",
|
|
||||||
"Auth fail,invalid data,End of IO Stream Read,Connection reset,socket is not established");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibvirtPropertiesBuilder(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibvirtPropertiesBuilder() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,180 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute.domain;
|
|
||||||
|
|
||||||
import static com.google.common.base.Predicates.notNull;
|
|
||||||
import static com.google.common.collect.Iterables.filter;
|
|
||||||
import static com.google.common.collect.Iterables.transform;
|
|
||||||
import static org.jclouds.libvirt.LibvirtConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
|
||||||
import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.functions.IdentityFunction;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
|
||||||
import org.jclouds.libvirt.Image;
|
|
||||||
import org.jclouds.libvirt.compute.functions.DomainToHardware;
|
|
||||||
import org.jclouds.libvirt.compute.functions.DomainToNodeMetadata;
|
|
||||||
import org.jclouds.libvirt.compute.functions.LibvirtImageToImage;
|
|
||||||
import org.jclouds.libvirt.compute.strategy.LibvirtComputeServiceAdapter;
|
|
||||||
import org.jclouds.location.Provider;
|
|
||||||
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
import org.libvirt.Domain;
|
|
||||||
import org.libvirt.LibvirtException;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class LibvirtComputeServiceContextModule extends
|
|
||||||
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Location> {
|
|
||||||
|
|
||||||
public LibvirtComputeServiceContextModule() {
|
|
||||||
super(Connect.class, Connect.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
super.configure();
|
|
||||||
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Domain, Image, Location>>() {
|
|
||||||
}).to(LibvirtComputeServiceAdapter.class);
|
|
||||||
bind(new TypeLiteral<Supplier<Location>>() {
|
|
||||||
}).to(OnlyLocationOrFirstZone.class);
|
|
||||||
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
|
|
||||||
}).to(DomainToNodeMetadata.class);
|
|
||||||
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
|
|
||||||
}).to(LibvirtImageToImage.class);
|
|
||||||
bind(new TypeLiteral<Function<Domain, Hardware>>() {
|
|
||||||
}).to(DomainToHardware.class);
|
|
||||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
|
||||||
}).to((Class) IdentityFunction.class);
|
|
||||||
|
|
||||||
// bind(ComputeService.class).to(LibvirtComputeService.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
|
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException {
|
|
||||||
// ConnectAuth connectAuth = null;
|
|
||||||
return new Connect(endpoint.toASCIIString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
|
||||||
String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
|
||||||
String hardwareId = searchForHardwareIdInDomainDir(domainDir, injector.getInstance(ParseSax.Factory.class),
|
|
||||||
injector.getProvider(UUIDHandler.class));
|
|
||||||
String image = searchForImageIdInDomainDir(domainDir);
|
|
||||||
return template.hardwareId(hardwareId).imageId(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String searchForImageIdInDomainDir(String domainDir) {
|
|
||||||
// TODO
|
|
||||||
return "1";
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private String searchForHardwareIdInDomainDir(String domainDir, final ParseSax.Factory factory,
|
|
||||||
final javax.inject.Provider<UUIDHandler> provider) {
|
|
||||||
|
|
||||||
// TODO: remove commons-io dependency
|
|
||||||
return Iterables.<String> getLast(filter(transform(FileUtils.listFiles(new File(domainDir),
|
|
||||||
new WildcardFileFilter("*.xml"), null), new Function<File, String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String apply(File input) {
|
|
||||||
try {
|
|
||||||
return factory.create(provider.get()).parse(new FileInputStream(input));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
// log error.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}), notNull()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UUIDHandler extends ParseSax.HandlerWithResult<String> {
|
|
||||||
private StringBuilder currentText = new StringBuilder();
|
|
||||||
|
|
||||||
private boolean inDomain;
|
|
||||||
private String uuid;
|
|
||||||
|
|
||||||
public String getResult() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
|
|
||||||
if (qName.equals("domain")) {
|
|
||||||
inDomain = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endElement(String uri, String localName, String qName) {
|
|
||||||
if (qName.equalsIgnoreCase("uuid") && inDomain) {
|
|
||||||
this.uuid = currentText.toString();
|
|
||||||
} else if (qName.equalsIgnoreCase("domain")) {
|
|
||||||
inDomain = false;
|
|
||||||
}
|
|
||||||
currentText = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void characters(char ch[], int start, int length) {
|
|
||||||
currentText.append(ch, start, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Map<String, URI> regions = newLinkedHashMap(); for (String region :
|
|
||||||
* Splitter.on(',').split(regionString)) { regions.put( region,
|
|
||||||
* URI.create(injector.getInstance(Key.get(String.class, Names.named(Constants.PROPERTY_ENDPOINT
|
|
||||||
* + "." + region))))); } return regions;
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute.functions;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpression;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.HardwareBuilder;
|
|
||||||
import org.jclouds.compute.domain.Processor;
|
|
||||||
import org.jclouds.compute.domain.Volume;
|
|
||||||
import org.jclouds.compute.domain.internal.VolumeImpl;
|
|
||||||
import org.libvirt.Domain;
|
|
||||||
import org.libvirt.LibvirtException;
|
|
||||||
import org.libvirt.StorageVol;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class DomainToHardware implements Function<Domain, Hardware> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hardware apply(Domain from) {
|
|
||||||
HardwareBuilder builder = new HardwareBuilder();
|
|
||||||
|
|
||||||
try {
|
|
||||||
builder.id(from.getUUIDString());
|
|
||||||
builder.providerId(from.getID() + "");
|
|
||||||
builder.name(from.getName());
|
|
||||||
List<Processor> processors = Lists.newArrayList();
|
|
||||||
for (int i = 0; i < from.getInfo().nrVirtCpu; i++) {
|
|
||||||
processors.add(new Processor(i + 1, 1));
|
|
||||||
}
|
|
||||||
builder.processors(processors);
|
|
||||||
|
|
||||||
builder.ram((int) from.getInfo().maxMem);
|
|
||||||
List<Volume> volumes = Lists.newArrayList();
|
|
||||||
XMLBuilder xmlBuilder = XMLBuilder.parse(new InputSource(new StringReader(from.getXMLDesc(0))));
|
|
||||||
Document doc = xmlBuilder.getDocument();
|
|
||||||
XPathExpression expr = XPathFactory.newInstance().newXPath().compile("//devices/disk[@device='disk']/source/@file");
|
|
||||||
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
|
||||||
String diskFileName = nodes.item(0).getNodeValue();
|
|
||||||
for (int i = 0; i < nodes.getLength(); i++) {
|
|
||||||
StorageVol storageVol = from.getConnect().storageVolLookupByPath(diskFileName);
|
|
||||||
String id = storageVol.getKey();
|
|
||||||
float size = Long.valueOf(storageVol.getInfo().capacity).floatValue();
|
|
||||||
volumes.add(new VolumeImpl(id, Volume.Type.LOCAL, size, null, true, false));
|
|
||||||
}
|
|
||||||
builder.volumes((List<Volume>) volumes);
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} catch (XPathExpressionException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} catch (ParserConfigurationException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} catch (SAXException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,138 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute.functions;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.parseGroupFromName;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.collect.FindResourceInSet;
|
|
||||||
import org.jclouds.collect.Memoized;
|
|
||||||
import org.jclouds.compute.domain.Hardware;
|
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.libvirt.Domain;
|
|
||||||
import org.libvirt.DomainInfo;
|
|
||||||
import org.libvirt.LibvirtException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Supplier;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class DomainToNodeMetadata implements Function<Domain, NodeMetadata> {
|
|
||||||
|
|
||||||
public static final Map<DomainInfo.DomainState, NodeState> domainStateToNodeState = ImmutableMap
|
|
||||||
.<DomainInfo.DomainState, NodeState> builder().put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING,
|
|
||||||
NodeState.RUNNING)//
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, NodeState.PENDING)//
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, NodeState.SUSPENDED)//
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, NodeState.SUSPENDED)//
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, NodeState.SUSPENDED)//
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_CRASHED, NodeState.ERROR)//
|
|
||||||
|
|
||||||
.put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, NodeState.UNRECOGNIZED)//
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Function<Domain, Hardware> findHardwareForDomain;
|
|
||||||
private final FindLocationForDomain findLocationForDomain;
|
|
||||||
private final FindImageForDomain findImageForDomain;
|
|
||||||
private final Map<String, Credentials> credentialStore;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
DomainToNodeMetadata(Map<String, Credentials> credentialStore, Function<Domain, Hardware> findHardwareForDomain,
|
|
||||||
FindLocationForDomain findLocationForDomain, FindImageForDomain findImageForDomain) {
|
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
|
||||||
this.findHardwareForDomain = checkNotNull(findHardwareForDomain, "findHardwareForDomain");
|
|
||||||
this.findLocationForDomain = checkNotNull(findLocationForDomain, "findLocationForDomain");
|
|
||||||
this.findImageForDomain = checkNotNull(findImageForDomain, "findImageForDomain");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NodeMetadata apply(Domain from) {
|
|
||||||
|
|
||||||
// convert the result object to a jclouds NodeMetadata
|
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
|
||||||
try {
|
|
||||||
builder.id(from.getUUIDString());
|
|
||||||
builder.providerId(from.getID() + "");
|
|
||||||
builder.name(from.getName());
|
|
||||||
builder.location(findLocationForDomain.apply(from));
|
|
||||||
builder.group(parseGroupFromName(from.getName()));
|
|
||||||
|
|
||||||
builder.operatingSystem(new OperatingSystemBuilder().description(from.getOSType()).build());
|
|
||||||
builder.hardware(findHardwareForDomain.apply(from));
|
|
||||||
|
|
||||||
builder.state(domainStateToNodeState.get(from.getInfo().state));
|
|
||||||
// builder.publicAddresses(ImmutableSet.<String> of(from.publicAddress));
|
|
||||||
// builder.privateAddresses(ImmutableSet.<String> of(from.privateAddress));
|
|
||||||
builder.credentials(credentialStore.get("node#" + from.getUUIDString()));
|
|
||||||
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class FindImageForDomain extends FindResourceInSet<Domain, Image> {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public FindImageForDomain(@Memoized Supplier<Set<? extends Image>> hardware) {
|
|
||||||
super(hardware);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Domain from, Image input) {
|
|
||||||
// TODO
|
|
||||||
// return input.getProviderId().equals(from.imageId + "");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public static class FindLocationForDomain extends FindResourceInSet<Domain, Location> {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public FindLocationForDomain(@Memoized Supplier<Set<? extends Location>> hardware) {
|
|
||||||
super(hardware);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(Domain from, Location input) {
|
|
||||||
// TODO
|
|
||||||
// return input.getId().equals(from.datacenter + "");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute.functions;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.compute.domain.Image;
|
|
||||||
import org.jclouds.compute.domain.ImageBuilder;
|
|
||||||
import org.jclouds.compute.domain.OperatingSystemBuilder;
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LibvirtImageToImage implements Function<org.jclouds.libvirt.Image, Image> {
|
|
||||||
@Resource
|
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Image apply(org.jclouds.libvirt.Image from) {
|
|
||||||
|
|
||||||
ImageBuilder builder = new ImageBuilder();
|
|
||||||
builder.ids(from.id + "");
|
|
||||||
builder.name(from.name);
|
|
||||||
builder.description(from.name);
|
|
||||||
|
|
||||||
OsFamily family = null;
|
|
||||||
try {
|
|
||||||
family = OsFamily.fromValue(from.name);
|
|
||||||
builder.operatingSystem(new OperatingSystemBuilder().name(from.name).family(family).description(from.name).build());
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
logger.debug("<< didn't match os(%s)", from);
|
|
||||||
}
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,282 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute.strategy;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.jclouds.libvirt.LibvirtConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.transform.TransformerException;
|
|
||||||
import javax.xml.xpath.XPathConstants;
|
|
||||||
import javax.xml.xpath.XPathExpression;
|
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
|
||||||
import javax.xml.xpath.XPathFactory;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeService;
|
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.domain.Credentials;
|
|
||||||
import org.jclouds.domain.Location;
|
|
||||||
import org.jclouds.libvirt.Image;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
import org.libvirt.Domain;
|
|
||||||
import org.libvirt.LibvirtException;
|
|
||||||
import org.libvirt.StoragePool;
|
|
||||||
import org.libvirt.StorageVol;
|
|
||||||
import org.libvirt.jna.Libvirt;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.name.Named;
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* defines the connection between the {@link Libvirt} implementation and the jclouds
|
|
||||||
* {@link ComputeService}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter<Domain, Domain, Image, Location> {
|
|
||||||
|
|
||||||
private final Connect client;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public LibvirtComputeServiceAdapter(Connect client, @Named(PROPERTY_LIBVIRT_DOMAIN_DIR) String domainDir) {
|
|
||||||
this.client = checkNotNull(client, "client");
|
|
||||||
System.out.println(domainDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Domain createNodeWithGroupEncodedIntoNameThenStoreCredentials(String tag, String name, Template template,
|
|
||||||
Map<String, Credentials> credentialStore) {
|
|
||||||
try {
|
|
||||||
String domainName = tag;
|
|
||||||
Domain domain = client.domainLookupByName(domainName);
|
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(domain.getXMLDesc(0))));
|
|
||||||
Document doc = builder.getDocument();
|
|
||||||
String xpathString = "//devices/disk[@device='disk']/source/@file";
|
|
||||||
XPathExpression expr = XPathFactory.newInstance().newXPath().compile(xpathString);
|
|
||||||
NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
|
|
||||||
String diskFileName = nodes.item(0).getNodeValue();
|
|
||||||
StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
|
|
||||||
|
|
||||||
// cloning volume
|
|
||||||
String poolName = storageVol.storagePoolLookupByVolume().getName();
|
|
||||||
StoragePool storagePool = client.storagePoolLookupByName(poolName);
|
|
||||||
StorageVol clonedVol = null;
|
|
||||||
boolean cloned = false;
|
|
||||||
int retry = 0;
|
|
||||||
while (!cloned && retry < 10) {
|
|
||||||
try {
|
|
||||||
clonedVol = cloneVolume(storagePool, storageVol);
|
|
||||||
cloned = true;
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
retry++;
|
|
||||||
Thread.sleep(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// define Domain
|
|
||||||
String xmlFinal = generateClonedDomainXML(domain.getXMLDesc(0), clonedVol);
|
|
||||||
Domain newDomain = client.domainDefineXML(xmlFinal);
|
|
||||||
newDomain.create();
|
|
||||||
// store the credentials so that later functions can use them
|
|
||||||
credentialStore.put(domain.getUUIDString() + "", new Credentials("identity", "credential"));
|
|
||||||
return newDomain;
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<Domain> listHardwareProfiles() {
|
|
||||||
return listNodes();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<Image> listImages() {
|
|
||||||
int i = 1;
|
|
||||||
try {
|
|
||||||
String[] domains = client.listDefinedDomains();
|
|
||||||
List<Image> images = Lists.newArrayList();
|
|
||||||
for (String domainName : domains) {
|
|
||||||
images.add(new Image(i++, domainName));
|
|
||||||
}
|
|
||||||
return images;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<Domain> listNodes() {
|
|
||||||
try {
|
|
||||||
List<Domain> domains = Lists.newArrayList();
|
|
||||||
for (String domain : client.listDefinedDomains()) {
|
|
||||||
domains.add(client.domainLookupByName(domain));
|
|
||||||
}
|
|
||||||
return domains;
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<Location> listLocations() {
|
|
||||||
return ImmutableSet.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Domain getNode(String id) {
|
|
||||||
Domain d = null;
|
|
||||||
try {
|
|
||||||
d = client.domainLookupByUUIDString(id);
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
if (e.getMessage().indexOf("Domain not found: no domain with matching uuid") != -1)
|
|
||||||
return null;
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
return d;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroyNode(String id) {
|
|
||||||
try {
|
|
||||||
client.domainLookupByUUIDString(id).destroy();
|
|
||||||
|
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(client.domainLookupByUUIDString(id)
|
|
||||||
.getXMLDesc(0))));
|
|
||||||
String diskFileName = builder.xpathFind("//devices/disk[@device='disk']/source").getElement().getAttribute(
|
|
||||||
"file");
|
|
||||||
StorageVol storageVol = client.storageVolLookupByPath(diskFileName);
|
|
||||||
storageVol.delete(0);
|
|
||||||
client.domainLookupByUUIDString(id).undefine();
|
|
||||||
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void rebootNode(String id) {
|
|
||||||
try {
|
|
||||||
client.domainLookupByUUIDString(id).reboot(0);
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static StorageVol cloneVolume(StoragePool storagePool, StorageVol from) throws LibvirtException,
|
|
||||||
XPathExpressionException, ParserConfigurationException, SAXException, IOException, TransformerException {
|
|
||||||
return storagePool.storageVolCreateXMLFrom(generateClonedVolumeXML(from.getXMLDesc(0)), from, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resumeNode(String id) {
|
|
||||||
try {
|
|
||||||
client.domainLookupByUUIDString(id).resume();
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void suspendNode(String id) {
|
|
||||||
try {
|
|
||||||
client.domainLookupByUUIDString(id).suspend();
|
|
||||||
} catch (LibvirtException e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String generateClonedVolumeXML(String fromXML) throws ParserConfigurationException, SAXException,
|
|
||||||
IOException, XPathExpressionException, TransformerException {
|
|
||||||
|
|
||||||
Properties outputProperties = generateOutputXMLProperties();
|
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML)));
|
|
||||||
String nodeNamingConvention = "%s-%s";
|
|
||||||
String tag = "-clone";
|
|
||||||
String suffix = String.format(nodeNamingConvention, tag, Integer.toHexString(new SecureRandom().nextInt(4095)));
|
|
||||||
builder.xpathFind("//volume/name").t(suffix);
|
|
||||||
builder.xpathFind("//volume/key").t(suffix);
|
|
||||||
builder.xpathFind("//volume/target/path").t(suffix);
|
|
||||||
|
|
||||||
return builder.asString(outputProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String generateClonedDomainXML(String fromXML, StorageVol clonedVol)
|
|
||||||
throws ParserConfigurationException, SAXException, IOException, XPathExpressionException,
|
|
||||||
TransformerException, LibvirtException {
|
|
||||||
|
|
||||||
Properties outputProperties = generateOutputXMLProperties();
|
|
||||||
|
|
||||||
XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML)));
|
|
||||||
|
|
||||||
String nodeNamingConvention = "%s-%s";
|
|
||||||
String tag = "-clone";
|
|
||||||
String suffix = String.format(nodeNamingConvention, tag, Integer.toHexString(new SecureRandom().nextInt(4095)));
|
|
||||||
builder.xpathFind("//domain/name").t(suffix);
|
|
||||||
// change uuid domain
|
|
||||||
Element oldChild = builder.xpathFind("//domain/uuid").getElement();
|
|
||||||
Node newNode = oldChild.cloneNode(true);
|
|
||||||
newNode.getFirstChild().setNodeValue(UUID.randomUUID().toString());
|
|
||||||
builder.getDocument().getDocumentElement().replaceChild(newNode, oldChild);
|
|
||||||
|
|
||||||
// String fromVolPath =
|
|
||||||
// builder.xpathFind("//domain/devices/disk/source").getElement().getAttribute("file");
|
|
||||||
builder.xpathFind("//domain/devices/disk/source").a("file", clonedVol.getPath());
|
|
||||||
// generate valid MAC address
|
|
||||||
String fromMACaddress = builder.xpathFind("//domain/devices/interface/mac").getElement().getAttribute("address");
|
|
||||||
String lastMACoctet = Integer.toHexString(new SecureRandom().nextInt(255));
|
|
||||||
builder.xpathFind("//domain/devices/interface/mac").a("address",
|
|
||||||
fromMACaddress.substring(0, fromMACaddress.lastIndexOf(":") + 1) + lastMACoctet);
|
|
||||||
return builder.asString(outputProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Properties generateOutputXMLProperties() {
|
|
||||||
Properties outputProperties = new Properties();
|
|
||||||
// Explicitly identify the output as an XML document
|
|
||||||
outputProperties.put(javax.xml.transform.OutputKeys.METHOD, "xml");
|
|
||||||
// Pretty-print the XML output (doesn't work in all cases)
|
|
||||||
outputProperties.put(javax.xml.transform.OutputKeys.INDENT, "yes");
|
|
||||||
// Get 2-space indenting when using the Apache transformer
|
|
||||||
outputProperties.put("{http://xml.apache.org/xslt}indent-amount", "2");
|
|
||||||
return outputProperties;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit")
|
|
||||||
public class LibvirtComputeServiceContextBuilderTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCanBuildWithComputeService() {
|
|
||||||
ComputeServiceContext context = new ComputeServiceContextFactory()
|
|
||||||
.createContext(new LibvirtComputeServiceContextSpec("test:///default", "identity", "credential"));
|
|
||||||
// System.err.println(context.getComputeService().
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCanBuildWithRestProperties() {
|
|
||||||
Properties restProperties = new Properties();
|
|
||||||
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.endpoint", "test:///default");
|
|
||||||
|
|
||||||
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("libvirt",
|
|
||||||
"identity", "credential");
|
|
||||||
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testProviderSpecificContextIsCorrectType() {
|
|
||||||
Properties restProperties = new Properties();
|
|
||||||
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.endpoint", "test:///default");
|
|
||||||
|
|
||||||
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("libvirt",
|
|
||||||
"identity", "credential");
|
|
||||||
|
|
||||||
RestContext<Connect, Connect> providerContext = context.getProviderSpecificContext();
|
|
||||||
|
|
||||||
assertEquals(providerContext.getApi().getClass(), Connect.class);
|
|
||||||
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,73 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
|
||||||
import org.libvirt.Connect;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "live", enabled = true, sequential = true)
|
|
||||||
public class LibvirtComputeServiceLiveTest extends BaseComputeServiceLiveTest {
|
|
||||||
public LibvirtComputeServiceLiveTest() {
|
|
||||||
provider = "libvirt";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Properties setupRestProperties() {
|
|
||||||
Properties restProperties = new Properties();
|
|
||||||
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
|
|
||||||
restProperties.setProperty("libvirt.endpoint", "test:///default");
|
|
||||||
return restProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTemplateBuilder() {
|
|
||||||
Template defaultTemplate = client.templateBuilder().build();
|
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
|
|
||||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
|
|
||||||
assertEquals(defaultTemplate.getLocation().getId(), "1");
|
|
||||||
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JschSshClientModule getSshModule() {
|
|
||||||
return new JschSshClientModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAssignability() throws Exception {
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
RestContext<Connect, Connect> goGridContext = new ComputeServiceContextFactory().createContext(provider,
|
|
||||||
identity, credential).getProviderSpecificContext();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.libvirt.compute;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
|
||||||
import org.jclouds.compute.domain.Template;
|
|
||||||
import org.jclouds.libvirt.compute.LibvirtComputeServiceContextSpec;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "live")
|
|
||||||
public class LibvirtExperimentLiveTest {
|
|
||||||
protected String provider = "libvirt";
|
|
||||||
protected String identity;
|
|
||||||
protected String credential;
|
|
||||||
protected String endpoint;
|
|
||||||
protected String apiVersion;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
protected void setupCredentials() {
|
|
||||||
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
|
|
||||||
credential = System.getProperty("test." + provider + ".credential");
|
|
||||||
endpoint = System.getProperty("test." + provider + ".endpoint");
|
|
||||||
apiVersion = System.getProperty("test." + provider + ".api-version");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAndExperiment() {
|
|
||||||
ComputeServiceContext context = null;
|
|
||||||
try {
|
|
||||||
context = new ComputeServiceContextFactory().createContext(new LibvirtComputeServiceContextSpec(
|
|
||||||
"qemu:///system", "identity", "credential"));
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* /* System.out.println("images " + context.getComputeService().listImages());
|
|
||||||
* System.out.println("nodes " + context.getComputeService().listNodes());
|
|
||||||
* System.out.println("hardware profiles " +
|
|
||||||
* context.getComputeService().listHardwareProfiles());
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* Template defaultTemplate = context.getComputeService().templateBuilder()
|
|
||||||
.hardwareId("d106ae67-5a1b-8f91-b311-83c93bcb0a1f").imageId("1") //.locationId("")
|
|
||||||
.build();*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We will probably make a default template out of properties at some point You can control
|
|
||||||
* the default template via overriding a method in standalonecomputeservicexontextmodule
|
|
||||||
*/
|
|
||||||
|
|
||||||
Set<? extends NodeMetadata> nodeMetadataSet = context.getComputeService().createNodesInGroup("tty", 1);
|
|
||||||
for (NodeMetadata nodeMetadata : nodeMetadataSet) {
|
|
||||||
/*
|
|
||||||
* context.getComputeService().suspendNode(nodeMetadata.getId());
|
|
||||||
* context.getComputeService().resumeNode(nodeMetadata.getId());
|
|
||||||
*/
|
|
||||||
context.getComputeService().destroyNode(nodeMetadata.getId());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (context != null)
|
|
||||||
context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,117 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
For more configuration infromation and examples see the Apache
|
|
||||||
Log4j website: http://logging.apache.org/log4j/
|
|
||||||
-->
|
|
||||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
|
||||||
debug="false">
|
|
||||||
|
|
||||||
<!-- A time/date based rolling appender -->
|
|
||||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
|
||||||
<param name="File" value="target/test-data/jclouds-wire.log" />
|
|
||||||
<param name="Append" value="true" />
|
|
||||||
|
|
||||||
<!-- Rollover at midnight each day -->
|
|
||||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
|
||||||
|
|
||||||
<param name="Threshold" value="TRACE" />
|
|
||||||
|
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
|
||||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
|
||||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The full pattern: Date MS Priority [Category]
|
|
||||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
|
||||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
|
||||||
-->
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- A time/date based rolling appender -->
|
|
||||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
|
||||||
<param name="File" value="target/test-data/jclouds.log" />
|
|
||||||
<param name="Append" value="true" />
|
|
||||||
|
|
||||||
<!-- Rollover at midnight each day -->
|
|
||||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
|
||||||
|
|
||||||
<param name="Threshold" value="TRACE" />
|
|
||||||
|
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
|
||||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
|
||||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The full pattern: Date MS Priority [Category]
|
|
||||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
|
||||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
|
||||||
-->
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
<!-- A time/date based rolling appender -->
|
|
||||||
<appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
|
||||||
<param name="File" value="target/test-data/jclouds-compute.log" />
|
|
||||||
<param name="Append" value="true" />
|
|
||||||
|
|
||||||
<!-- Rollover at midnight each day -->
|
|
||||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
|
||||||
|
|
||||||
<param name="Threshold" value="TRACE" />
|
|
||||||
|
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
|
||||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
|
||||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The full pattern: Date MS Priority [Category]
|
|
||||||
(Thread:NDC) Message\n <param name="ConversionPattern"
|
|
||||||
value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
|
|
||||||
-->
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
|
|
||||||
<appender-ref ref="COMPUTEFILE" />
|
|
||||||
</appender>
|
|
||||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
|
||||||
<appender-ref ref="FILE" />
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
|
||||||
<appender-ref ref="WIREFILE" />
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- ================ -->
|
|
||||||
<!-- Limit categories -->
|
|
||||||
<!-- ================ -->
|
|
||||||
|
|
||||||
<category name="org.jclouds">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNC" />
|
|
||||||
</category>
|
|
||||||
|
|
||||||
<category name="jclouds.headers">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNCWIRE" />
|
|
||||||
</category>
|
|
||||||
<category name="jclouds.wire">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNCWIRE" />
|
|
||||||
</category>
|
|
||||||
|
|
||||||
<category name="jclouds.compute">
|
|
||||||
<priority value="TRACE" />
|
|
||||||
<appender-ref ref="ASYNCCOMPUTE" />
|
|
||||||
</category>
|
|
||||||
<!-- ======================= -->
|
|
||||||
<!-- Setup the Root category -->
|
|
||||||
<!-- ======================= -->
|
|
||||||
|
|
||||||
<root>
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
</root>
|
|
||||||
|
|
||||||
</log4j:configuration>
|
|
|
@ -1,25 +0,0 @@
|
||||||
====
|
|
||||||
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.
|
|
||||||
====
|
|
||||||
|
|
||||||
#
|
|
||||||
# The jclouds provider for the Nirvanix Storage Delivery Network (http://www.nirvanix.com/products-services/storage-delivery-network/index.aspx).
|
|
||||||
#
|
|
||||||
# TODO: Implementation status.
|
|
||||||
# TODO: Supported features.
|
|
||||||
# TODO: Usage example.
|
|
|
@ -1,126 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<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/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-project</artifactId>
|
|
||||||
<version>1.7.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../../project/pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<groupId>org.jclouds.provider</groupId>
|
|
||||||
<artifactId>nirvanix</artifactId>
|
|
||||||
<name>jclouds nirvanix storage delivery network core</name>
|
|
||||||
<description>jclouds Core components to access nirvanix nirvanix</description>
|
|
||||||
<packaging>bundle</packaging>
|
|
||||||
|
|
||||||
<!-- bootstrapping: need to fetch the project POM -->
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>jclouds-sona-snapshots-nexus</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<test.nirvanix.endpoint>http://services.nirvanix.com</test.nirvanix.endpoint>
|
|
||||||
<test.nirvanix.api-version>2.5.6</test.nirvanix.api-version>
|
|
||||||
<test.nirvanix.build-version></test.nirvanix.build-version>
|
|
||||||
<test.nirvanix.identity>FIXME</test.nirvanix.identity>
|
|
||||||
<test.nirvanix.credential> FIXME </test.nirvanix.credential>
|
|
||||||
|
|
||||||
<jclouds.osgi.export>org.jclouds.nirvanix.sdn*;version="${project.version}"</jclouds.osgi.export>
|
|
||||||
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-blobstore</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-blobstore</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds.driver</groupId>
|
|
||||||
<artifactId>jclouds-log4j</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>live</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>integration</id>
|
|
||||||
<phase>integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<test.nirvanix.endpoint>${test.nirvanix.endpoint}</test.nirvanix.endpoint>
|
|
||||||
<test.nirvanix.api-version>${test.nirvanix.api-version}</test.nirvanix.api-version>
|
|
||||||
<test.nirvanix.build-version>${test.nirvanix.build-version}</test.nirvanix.build-version>
|
|
||||||
<test.nirvanix.identity>${test.nirvanix.identity}</test.nirvanix.identity>
|
|
||||||
<test.nirvanix.credential>${test.nirvanix.credential}</test.nirvanix.credential>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,112 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.binders.BindBlobToMultipartForm;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.nirvanix.sdn.binders.BindMetadataToQueryParams;
|
|
||||||
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
|
|
||||||
import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest;
|
|
||||||
import org.jclouds.nirvanix.sdn.filters.InsertUserContextIntoPath;
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseMetadataFromJsonResponse;
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseUploadInfoFromJsonResponse;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNQueryParams;
|
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
|
||||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
|
||||||
import org.jclouds.rest.annotations.SkipEncoding;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides asynchronous access to Nirvanix SDN resources via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @see SDNClient
|
|
||||||
* @see <a href="http://developer.nirvanix.com/sitefiles/1000/API.html" />
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@RequestFilters(AddSessionTokenToRequest.class)
|
|
||||||
@SkipEncoding( { '/', ':' })
|
|
||||||
@QueryParams(keys = SDNQueryParams.OUTPUT, values = "json")
|
|
||||||
public interface SDNAsyncClient {
|
|
||||||
@Provides
|
|
||||||
public Blob newBlob();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see SDNClient#getStorageNode
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/ws/IMFS/GetStorageNode.ashx")
|
|
||||||
@ResponseParser(ParseUploadInfoFromJsonResponse.class)
|
|
||||||
ListenableFuture<UploadInfo> getStorageNode(
|
|
||||||
@QueryParam(SDNQueryParams.DESTFOLDERPATH) String folderPath,
|
|
||||||
@QueryParam(SDNQueryParams.SIZEBYTES) long size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see SDNClient#upload
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("/Upload.ashx")
|
|
||||||
ListenableFuture<Void> upload(@EndpointParam URI endpoint,
|
|
||||||
@QueryParam(SDNQueryParams.UPLOADTOKEN) String uploadToken,
|
|
||||||
@QueryParam(SDNQueryParams.DESTFOLDERPATH) String folderPath,
|
|
||||||
@BinderParam(BindBlobToMultipartForm.class) Blob blob);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see SDNClient#setMetadata
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/ws/Metadata/SetMetadata.ashx")
|
|
||||||
@QueryParams(keys = SDNQueryParams.PATH, values = "{path}")
|
|
||||||
ListenableFuture<Void> setMetadata(@PathParam("path") String path,
|
|
||||||
@BinderParam(BindMetadataToQueryParams.class) Map<String, String> metadata);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see SDNClient#getMetadata
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/ws/Metadata/GetMetadata.ashx")
|
|
||||||
@ResponseParser(ParseMetadataFromJsonResponse.class)
|
|
||||||
@QueryParams(keys = SDNQueryParams.PATH, values = "{path}")
|
|
||||||
ListenableFuture<Map<String, String>> getMetadata(@PathParam("path") String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see SDNClient#getFile
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@Path("/{path}")
|
|
||||||
@OverrideRequestFilters
|
|
||||||
@RequestFilters(InsertUserContextIntoPath.class)
|
|
||||||
ListenableFuture<String> getFile(@PathParam("path") String path);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNQueryParams;
|
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides asynchronous access to Nirvanix SDN resources via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @see <a href="http://developer.nirvanix.com/sitefiles/1000/API.html" />
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@QueryParams(keys = SDNQueryParams.OUTPUT, values = "json")
|
|
||||||
public interface SDNAuthAsyncClient {
|
|
||||||
|
|
||||||
public interface AuthenticationResponse {
|
|
||||||
@SessionToken
|
|
||||||
String getSessionToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@ResponseParser(ParseSessionTokenFromJsonResponse.class)
|
|
||||||
@Path("/ws/Authentication/Login.ashx")
|
|
||||||
ListenableFuture<String> authenticate(@QueryParam(SDNQueryParams.APPKEY) String appKey,
|
|
||||||
@QueryParam(SDNQueryParams.USERNAME) String user,
|
|
||||||
@QueryParam(SDNQueryParams.PASSWORD) String password);
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
|
||||||
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides access to Nirvanix SDN resources via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @see <a href="http://developer.nirvanix.com/sitefiles/1000/API.html" />
|
|
||||||
* @see SDNAsyncClient
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
|
||||||
public interface SDNClient {
|
|
||||||
@Provides
|
|
||||||
public Blob newBlob();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GetStorageNode method is used to determine which storage node a file should be uploaded
|
|
||||||
* to. It returns the host to upload to and an Upload Token that will be used to authenticate.
|
|
||||||
*/
|
|
||||||
UploadInfo getStorageNode(String folderPath, long size);
|
|
||||||
|
|
||||||
void upload(URI endpoint, String uploadToken, String folderPath, Blob blob);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The SetMetadata method is used to set specified metadata for a file or folder.
|
|
||||||
*/
|
|
||||||
void setMetadata(String path, Map<String, String> metadata);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The GetMetadata method is used to retrieve all metadata from a file or folder.
|
|
||||||
*/
|
|
||||||
Map<String, String> getMetadata(String path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the contents of a file
|
|
||||||
*/
|
|
||||||
String getFile(String path);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNAuthRestClientModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
|
||||||
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class SDNContextBuilder extends RestContextBuilder<SDNClient, SDNAsyncClient> {
|
|
||||||
|
|
||||||
public SDNContextBuilder(Properties props) {
|
|
||||||
super(SDNClient.class, SDNAsyncClient.class, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void addClientModule(List<Module> modules) {
|
|
||||||
modules.add(new SDNAuthRestClientModule());
|
|
||||||
modules.add(new SDNRestClientModule());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds properties used in SDN Clients
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class SDNPropertiesBuilder extends PropertiesBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Properties defaultProperties() {
|
|
||||||
Properties properties = super.defaultProperties();
|
|
||||||
properties.setProperty(Constants.PROPERTY_API_VERSION, "2.5.6");
|
|
||||||
properties.setProperty(Constants.PROPERTY_ENDPOINT, "http://services.nirvanix.com");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SDNPropertiesBuilder(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a SDN resource.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface SessionToken {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.binders;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.utils.ModifyRequest;
|
|
||||||
import org.jclouds.rest.Binder;
|
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class BindMetadataToQueryParams implements Binder {
|
|
||||||
private final Provider<UriBuilder> builder;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
BindMetadataToQueryParams(Provider<UriBuilder> builder) {
|
|
||||||
this.builder = builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
|
||||||
checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Maps!");
|
|
||||||
Map<String, String> userMetadata = (Map<String, String>) input;
|
|
||||||
List<String> metadata = Lists.newArrayList();
|
|
||||||
for (Entry<String, String> entry : userMetadata.entrySet()) {
|
|
||||||
metadata.add(String.format("%s:%s", entry.getKey().toLowerCase(), entry.getValue()));
|
|
||||||
}
|
|
||||||
return ModifyRequest.addQueryParam(request, "metadata", metadata, builder.get());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,97 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.config;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNAuthAsyncClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the SDN authentication service connection, including logging and http transport.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@RequiresHttp
|
|
||||||
public class SDNAuthRestClientModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_APPKEY)
|
|
||||||
public String credentials1(@Named(Constants.PROPERTY_IDENTITY) String identity) {
|
|
||||||
List<String> parts = Lists.newArrayList(Splitter.on('/').split(identity));
|
|
||||||
if (parts.size() != 3) {
|
|
||||||
throw new IllegalArgumentException("identity syntax is appkey/appname/username");
|
|
||||||
}
|
|
||||||
return parts.get(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_APPNAME)
|
|
||||||
public String credentials2(@Named(Constants.PROPERTY_IDENTITY) String identity) {
|
|
||||||
List<String> parts = Lists.newArrayList(Splitter.on('/').split(identity));
|
|
||||||
if (parts.size() != 3) {
|
|
||||||
throw new IllegalArgumentException("identity syntax is appkey/appname/username");
|
|
||||||
}
|
|
||||||
return parts.get(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_USERNAME)
|
|
||||||
public String credentials3(@Named(Constants.PROPERTY_IDENTITY) String identity) {
|
|
||||||
List<String> parts = Lists.newArrayList(Splitter.on('/').split(identity));
|
|
||||||
if (parts.size() != 3) {
|
|
||||||
throw new IllegalArgumentException("identity syntax is appkey/appname/username");
|
|
||||||
}
|
|
||||||
return parts.get(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@SessionToken
|
|
||||||
protected String provideSessionToken(AsyncClientFactory factory,
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_APPKEY) String appKey,
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_USERNAME) String username,
|
|
||||||
@Named(Constants.PROPERTY_CREDENTIAL) String password) throws InterruptedException,
|
|
||||||
ExecutionException, TimeoutException {
|
|
||||||
return factory.create(SDNAuthAsyncClient.class).authenticate(appKey, username, password).get(
|
|
||||||
20, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.config;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNClient;
|
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the SDN authentication service connection, including logging and http transport.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@RequiresHttp
|
|
||||||
public class SDNRestClientModule extends RestClientModule<SDNClient, SDNAsyncClient> {
|
|
||||||
|
|
||||||
public SDNRestClientModule() {
|
|
||||||
super(SDNClient.class, SDNAsyncClient.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
install(new BlobStoreObjectModule());
|
|
||||||
super.configure();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void bindRetryHandlers() {
|
|
||||||
// TODO retry on 401 by AuthenticateRequest.update()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
public class UploadInfo {
|
|
||||||
private final String token;
|
|
||||||
private final URI host;
|
|
||||||
|
|
||||||
public UploadInfo(String token, URI host) {
|
|
||||||
this.token = token;
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getHost() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,95 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.filters;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import com.google.commons.util.concurrent.Atomitcs;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpException;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
|
||||||
import org.jclouds.http.utils.ModifyRequest;
|
|
||||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNQueryParams;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the Session Token to the request. This will update the Session Token before 20 minutes is
|
|
||||||
* up.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class AddSessionTokenToRequest implements HttpRequestFilter {
|
|
||||||
|
|
||||||
private final Provider<String> authTokenProvider;
|
|
||||||
private final Provider<UriBuilder> builder;
|
|
||||||
|
|
||||||
public final long BILLION = 1000000000;
|
|
||||||
public final long MINUTES = 60 * BILLION;
|
|
||||||
|
|
||||||
private final AtomicReference<String> authToken;
|
|
||||||
private final AtomicLong trigger = new AtomicLong(0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the time update service. Nirvanix clocks need to be 20 minutes of the session token.
|
|
||||||
* This is not performed per-request, as creation of the token is a slow, synchronized command.
|
|
||||||
*/
|
|
||||||
synchronized void updateIfTimeOut() {
|
|
||||||
|
|
||||||
if (trigger.get() - System.nanoTime() <= 0) {
|
|
||||||
createNewToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a hotspot when submitted concurrently, so be lazy.
|
|
||||||
// session tokens expire in 20 minutes of no use, but let's be a little paranoid and go 19
|
|
||||||
public String createNewToken() {
|
|
||||||
authToken.set(authTokenProvider.get());
|
|
||||||
trigger.set(System.nanoTime() + System.nanoTime() + 19 * MINUTES);
|
|
||||||
return authToken.get();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSessionToken() {
|
|
||||||
updateIfTimeOut();
|
|
||||||
return authToken.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public AddSessionTokenToRequest(@SessionToken Provider<String> authTokenProvider, Provider<UriBuilder> builder) {
|
|
||||||
this.builder = builder;
|
|
||||||
this.authTokenProvider = authTokenProvider;
|
|
||||||
authToken = Atomics.newReference();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
|
||||||
return ModifyRequest.addQueryParam(request, SDNQueryParams.SESSIONTOKEN, getSessionToken(), builder.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.filters;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpException;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the Session Token to the request. This will update the Session Token before 20 minutes is
|
|
||||||
* up.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class InsertUserContextIntoPath implements HttpRequestFilter {
|
|
||||||
|
|
||||||
private final AddSessionTokenToRequest sessionManager;
|
|
||||||
private final String pathPrefix;
|
|
||||||
private final Provider<UriBuilder> builder;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public InsertUserContextIntoPath(AddSessionTokenToRequest sessionManager,
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_APPNAME) String appname,
|
|
||||||
@Named(SDNConstants.PROPERTY_SDN_USERNAME) String username, Provider<UriBuilder> builder) {
|
|
||||||
this.builder = builder;
|
|
||||||
this.sessionManager = sessionManager;
|
|
||||||
this.pathPrefix = String.format("/%s/%s/", appname, username);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HttpRequest filter(HttpRequest request) throws HttpException {
|
|
||||||
String sessionToken = sessionManager.getSessionToken();
|
|
||||||
int prefixIndex = request.getEndpoint().getPath().indexOf(pathPrefix);
|
|
||||||
String path;
|
|
||||||
if (prefixIndex == -1) { // addToken
|
|
||||||
path = "/" + sessionToken + pathPrefix + request.getEndpoint().getPath().substring(1);
|
|
||||||
} else { // replace token
|
|
||||||
path = "/" + sessionToken + request.getEndpoint().getPath().substring(prefixIndex);
|
|
||||||
}
|
|
||||||
URI newEndpoint = builder.get().uri(request.getEndpoint()).replacePath(path).build();
|
|
||||||
return request.toBuilder().endpoint(newEndpoint).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.ParseJson;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This parses a Map of Metadata from a Nirvanix response
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ParseMetadataFromJsonResponse implements
|
|
||||||
Function<HttpResponse, Map<String, String>> {
|
|
||||||
|
|
||||||
private final ParseJson<Response> json;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ParseMetadataFromJsonResponse(ParseJson<Response> json) {
|
|
||||||
this.json = json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, String> apply(HttpResponse arg0) {
|
|
||||||
Response response = json.apply(arg0);
|
|
||||||
if (response.ResponseCode == null || response.ResponseCode != 0)
|
|
||||||
throw new RuntimeException("bad response code: "
|
|
||||||
+ response.ResponseCode);
|
|
||||||
Map<String, String> metadata = Maps.newHashMap();
|
|
||||||
for (Map<String, String> keyValue : response.Metadata) {
|
|
||||||
metadata.put(keyValue.get("Type"), keyValue.get("Value"));
|
|
||||||
}
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Response {
|
|
||||||
Integer ResponseCode;
|
|
||||||
List<Map<String, String>> Metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.ParseJson;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This parses the Nirvanix SessionToken from a gson string.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ParseSessionTokenFromJsonResponse implements
|
|
||||||
Function<HttpResponse, String> {
|
|
||||||
|
|
||||||
private final ParseJson<Response> json;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ParseSessionTokenFromJsonResponse(ParseJson<Response> json) {
|
|
||||||
this.json = json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String apply(HttpResponse arg0) {
|
|
||||||
Response response = json.apply(arg0);
|
|
||||||
if (response.ResponseCode == null || response.ResponseCode != 0)
|
|
||||||
throw new RuntimeException("bad response code: "
|
|
||||||
+ response.ResponseCode);
|
|
||||||
return response.SessionToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Response {
|
|
||||||
Integer ResponseCode;
|
|
||||||
String SessionToken;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.ParseJson;
|
|
||||||
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This parses the Nirvanix Upload host and token from a gson string.
|
|
||||||
*
|
|
||||||
* @see UploadInfo
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ParseUploadInfoFromJsonResponse implements
|
|
||||||
Function<HttpResponse, UploadInfo> {
|
|
||||||
|
|
||||||
private final ParseJson<Response> json;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
ParseUploadInfoFromJsonResponse(ParseJson<Response> json) {
|
|
||||||
this.json = json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UploadInfo apply(HttpResponse arg0) {
|
|
||||||
Response response = json.apply(arg0);
|
|
||||||
if (response.ResponseCode == null || response.ResponseCode != 0)
|
|
||||||
throw new RuntimeException("bad response code: "
|
|
||||||
+ response.ResponseCode);
|
|
||||||
return new UploadInfo(response.GetStorageNode.get("UploadToken"), URI
|
|
||||||
.create("https://" + response.GetStorageNode.get("UploadHost")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Response {
|
|
||||||
Integer ResponseCode;
|
|
||||||
Map<String, String> GetStorageNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.reference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration properties and constants used in SDN connections.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public interface SDNConstants {
|
|
||||||
public static final String PROPERTY_SDN_USERNAME = "jclouds.nirvanix.sdn.username";
|
|
||||||
public static final String PROPERTY_SDN_APPKEY = "jclouds.nirvanix.sdn.appkey";
|
|
||||||
public static final String PROPERTY_SDN_APPNAME = "jclouds.nirvanix.sdn.appname";
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.reference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query parameters common to SDN apis.
|
|
||||||
*
|
|
||||||
* @see <a href="http://developer.nirvanix.com/sitefiles/1000/API.html" />
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface SDNQueryParams {
|
|
||||||
public static final String USERNAME = "username";
|
|
||||||
public static final String PASSWORD = "password";
|
|
||||||
public static final String APPKEY = "appKey";
|
|
||||||
public static final String OUTPUT = "output";
|
|
||||||
public static final String SESSIONTOKEN = "sessionToken";
|
|
||||||
public static final String DESTFOLDERPATH = "destFolderPath";
|
|
||||||
public static final String PATH = "path";
|
|
||||||
public static final String SIZEBYTES = "sizeBytes";
|
|
||||||
public static final String UPLOADTOKEN = "uploadToken";
|
|
||||||
}
|
|
|
@ -1,188 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
|
||||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.filters.AddSessionTokenToRequest;
|
|
||||||
import org.jclouds.nirvanix.sdn.filters.InsertUserContextIntoPath;
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseMetadataFromJsonResponse;
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseUploadInfoFromJsonResponse;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
|
||||||
import org.jclouds.rest.RestContextFactory;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.SDNClient")
|
|
||||||
public class SDNAsyncClientTest extends RestClientTest<SDNAsyncClient> {
|
|
||||||
|
|
||||||
public void testGetStorageNode() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAsyncClient.class.getMethod("getStorageNode", String.class, long.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, "adriansmovies", 734859264);
|
|
||||||
|
|
||||||
assertRequestLineEquals(
|
|
||||||
request,
|
|
||||||
"GET http://services.nirvanix.com/ws/IMFS/GetStorageNode.ashx?output=json&destFolderPath=adriansmovies&sizeBytes=734859264 HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseUploadInfoFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUpload() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAsyncClient.class.getMethod("upload", URI.class, String.class, String.class, Blob.class);
|
|
||||||
Blob blob = BindBlobToMultipartFormTest.TEST_BLOB;
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://uploader"), "token", "adriansmovies",
|
|
||||||
blob);
|
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
|
||||||
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
StringBuilder expects = new StringBuilder();
|
|
||||||
expects.append("----JCLOUDS--\r\n");
|
|
||||||
expects.append("Content-Disposition: form-data; name=\"hello\"\r\n");
|
|
||||||
expects.append("Content-Type: text/plain\r\n\r\n");
|
|
||||||
expects.append("hello\r\n");
|
|
||||||
expects.append("----JCLOUDS----\r\n");
|
|
||||||
|
|
||||||
assertPayloadEquals(request, expects.toString(), "multipart/form-data; boundary=--JCLOUDS--", false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSetMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAsyncClient.class.getMethod("setMetadata", String.class, Map.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi", ImmutableMap.of("Chef",
|
|
||||||
"Kawasaki"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(
|
|
||||||
request,
|
|
||||||
"GET http://services.nirvanix.com/ws/Metadata/SetMetadata.ashx?output=json&path=adriansmovies/sushi.avi&metadata=chef:Kawasaki HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAsyncClient.class.getMethod("getMetadata", String.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi");
|
|
||||||
|
|
||||||
assertRequestLineEquals(request,
|
|
||||||
"GET http://services.nirvanix.com/ws/Metadata/GetMetadata.ashx?output=json&path=adriansmovies/sushi.avi HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseMetadataFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetFile() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAsyncClient.class.getMethod("getFile", String.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, "adriansmovies/sushi.avi");
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://services.nirvanix.com/adriansmovies/sushi.avi?output=json HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnStringIf2xx.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
assertEquals(request.getFilters().size(), 1);
|
|
||||||
assertEquals(request.getFilters().get(0).getClass(), InsertUserContextIntoPath.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFilters(HttpRequest request) {
|
|
||||||
assertEquals(request.getFilters().size(), 1);
|
|
||||||
assertEquals(request.getFilters().get(0).getClass(), AddSessionTokenToRequest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>> createTypeLiteral() {
|
|
||||||
return new TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>>() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Module createModule() {
|
|
||||||
return new TestSDNRestClientModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresHttp
|
|
||||||
@ConfiguresRestClient
|
|
||||||
static class TestSDNRestClientModule extends SDNRestClientModule {
|
|
||||||
@Override
|
|
||||||
public void configure() {
|
|
||||||
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
|
|
||||||
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNAuthenticationLiveTest.SDNAuthClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.functions.ParseSessionTokenFromJsonResponse;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code JaxrsAnnotationProcessor}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.SDNAuthentication")
|
|
||||||
public class SDNAuthAsyncClientTest extends RestClientTest<SDNAuthAsyncClient> {
|
|
||||||
|
|
||||||
public void testAuthenticate() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = SDNAuthAsyncClient.class.getMethod("authenticate", String.class, String.class, String.class);
|
|
||||||
GeneratedHttpRequest httpRequest = processor.createRequest(method, "apple", "foo", "bar");
|
|
||||||
assertRequestLineEquals(httpRequest,
|
|
||||||
"GET http://localhost:8080/ws/Authentication/Login.ashx?output=json&appKey=apple&password=bar&username=foo HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseSessionTokenFromJsonResponse.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFilters(HttpRequest request) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TypeLiteral<RestAnnotationProcessor<SDNAuthAsyncClient>> createTypeLiteral() {
|
|
||||||
return new TypeLiteral<RestAnnotationProcessor<SDNAuthAsyncClient>>() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> createContextSpec() {
|
|
||||||
return contextSpec("test", "http://localhost:8080", "1", "", "identity", "credential", SDNAuthClient.class,
|
|
||||||
SDNAuthAsyncClient.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,84 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
|
||||||
import static org.jclouds.rest.RestContextFactory.createContextBuilder;
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.concurrent.MoreExecutors;
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.base.Splitter;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code SDNAuthentication}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "live", testName = "sdn.SDNAuthenticationLiveTest")
|
|
||||||
public class SDNAuthenticationLiveTest {
|
|
||||||
|
|
||||||
private RestContext<SDNAuthClient, SDNAuthAsyncClient> context;
|
|
||||||
|
|
||||||
@Timeout(duration = 10, timeUnit = TimeUnit.SECONDS)
|
|
||||||
public interface SDNAuthClient {
|
|
||||||
|
|
||||||
String authenticate(String appKey, String user, String password);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String credential;
|
|
||||||
private String identity;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testAuthentication() throws Exception {
|
|
||||||
ArrayList<String> list = Lists.newArrayList(Splitter.on('/').split(credential));
|
|
||||||
String response = context.getApi().authenticate(list.get(0), list.get(1), identity);
|
|
||||||
assertNotNull(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
void setupFactory() {
|
|
||||||
|
|
||||||
String endpoint = "http://services.nirvanix.com";
|
|
||||||
identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
|
|
||||||
credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
|
|
||||||
|
|
||||||
RestContextSpec<SDNAuthClient, SDNAuthAsyncClient> contextSpec = contextSpec("test", endpoint, "1", "", identity,
|
|
||||||
credential, SDNAuthClient.class, SDNAuthAsyncClient.class);
|
|
||||||
|
|
||||||
context = createContextBuilder(
|
|
||||||
contextSpec,
|
|
||||||
ImmutableSet.<Module> of(new Log4JLoggingModule(), new ExecutorServiceModule(MoreExecutors
|
|
||||||
.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()))).buildContext();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,101 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertNotNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
|
||||||
import org.jclouds.encryption.internal.Base64;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
|
|
||||||
import org.jclouds.rest.RestContext;
|
|
||||||
import org.jclouds.rest.RestContextFactory;
|
|
||||||
import org.testng.annotations.BeforeGroups;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code SDNClient}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "live", sequential = true, testName = "sdn.SDNClientLiveTest")
|
|
||||||
public class SDNClientLiveTest {
|
|
||||||
|
|
||||||
protected SDNClient connection;
|
|
||||||
private String containerPrefix = BaseBlobStoreIntegrationTest.CONTAINER_PREFIX;
|
|
||||||
|
|
||||||
URI container1;
|
|
||||||
URI container2;
|
|
||||||
private RestContext<SDNClient, SDNAsyncClient> context;
|
|
||||||
|
|
||||||
@BeforeGroups(groups = { "live" })
|
|
||||||
public void setupClient() {
|
|
||||||
|
|
||||||
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), "jclouds.test.identity");
|
|
||||||
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), "jclouds.test.credential");
|
|
||||||
|
|
||||||
this.context = new RestContextFactory().createContext("sdn", identity, credential, ImmutableSet
|
|
||||||
.<Module> of(new Log4JLoggingModule()));
|
|
||||||
this.connection = context.getApi();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUploadToken() throws InterruptedException, ExecutionException, TimeoutException, IOException {
|
|
||||||
String containerName = containerPrefix + ".testObjectOperations";
|
|
||||||
long size = 1024;
|
|
||||||
|
|
||||||
UploadInfo uploadInfo = connection.getStorageNode(containerName, size);
|
|
||||||
assertNotNull(uploadInfo.getHost());
|
|
||||||
assertNotNull(uploadInfo.getToken());
|
|
||||||
|
|
||||||
Blob blob = connection.newBlob();
|
|
||||||
blob.getMetadata().setName("test.txt");
|
|
||||||
blob.setPayload("value");
|
|
||||||
Payloads.calculateMD5(blob);
|
|
||||||
|
|
||||||
byte[] md5 = blob.getMetadata().getContentMetadata().getContentMD5();
|
|
||||||
connection.upload(uploadInfo.getHost(), uploadInfo.getToken(), containerName, blob);
|
|
||||||
|
|
||||||
Map<String, String> metadata = connection.getMetadata(containerName + "/test.txt");
|
|
||||||
assertEquals(metadata.get("MD5"), Base64.encodeBytes(md5));
|
|
||||||
|
|
||||||
String content = connection.getFile(containerName + "/test.txt");
|
|
||||||
assertEquals(content, "value");
|
|
||||||
|
|
||||||
metadata = ImmutableMap.of("chef", "sushi", "foo", "bar");
|
|
||||||
connection.setMetadata(containerName + "/test.txt", metadata);
|
|
||||||
|
|
||||||
metadata = connection.getMetadata(containerName + "/test.txt");
|
|
||||||
assertEquals(metadata.get("MD5"), Base64.encodeBytes(md5));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.binders;
|
|
||||||
|
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.inject.Provider;
|
|
||||||
import javax.ws.rs.HttpMethod;
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.sun.jersey.api.uri.UriBuilderImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code BindMetadataToQueryParams}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.BindMetadataToQueryParamsTest")
|
|
||||||
public class BindMetadataToQueryParamsTest {
|
|
||||||
|
|
||||||
@Test(expectedExceptions = IllegalArgumentException.class)
|
|
||||||
public void testMustBeMap() {
|
|
||||||
BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null);
|
|
||||||
HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost"), new char[] { '/', ':' });
|
|
||||||
binder.bindToRequest(request, new File("foo"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCorrect() throws SecurityException, NoSuchMethodException {
|
|
||||||
|
|
||||||
HttpRequest request = new HttpRequest("GET", URI.create("http://momma/"), new char[] { '/', ':' });
|
|
||||||
|
|
||||||
BindMetadataToQueryParams binder = new BindMetadataToQueryParams(new Provider<UriBuilder>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UriBuilder get() {
|
|
||||||
return new UriBuilderImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
request = binder.bindToRequest(request, ImmutableMap.of("imageName", "foo", "serverId", "2"));
|
|
||||||
|
|
||||||
assertEquals(request.getRequestLine(), "GET http://momma/?metadata=imagename:foo&metadata=serverid:2 HTTP/1.1");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class })
|
|
||||||
public void testNullIsBad() {
|
|
||||||
BindMetadataToQueryParams binder = new BindMetadataToQueryParams(null);
|
|
||||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
|
||||||
binder.bindToRequest(request, null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.filters;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
|
||||||
import org.jclouds.rest.RestContextFactory;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.DataProvider;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Key;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "AddSessionTokenToRequestTest")
|
|
||||||
public class AddSessionTokenToRequestTest extends RestClientTest<SDNAsyncClient> {
|
|
||||||
|
|
||||||
private static interface TestService {
|
|
||||||
@POST
|
|
||||||
public void foo(@EndpointParam URI endpoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
@DataProvider
|
|
||||||
public Object[][] dataProvider() throws SecurityException, NoSuchMethodException {
|
|
||||||
|
|
||||||
RestAnnotationProcessor<TestService> factory = injector.getInstance(Key
|
|
||||||
.get(new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
|
||||||
}));
|
|
||||||
|
|
||||||
Method method = TestService.class.getMethod("foo", URI.class);
|
|
||||||
return new Object[][] { { factory.createRequest(method, new Object[] { URI.create("https://host:443") }) },
|
|
||||||
{ factory.createRequest(method, new Object[] { URI.create("https://host/path") }) },
|
|
||||||
{ factory.createRequest(method, new Object[] { URI.create("https://host/?query") })
|
|
||||||
|
|
||||||
} };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(dataProvider = "dataProvider")
|
|
||||||
public void testRequests(HttpRequest request) {
|
|
||||||
String token = filter.getSessionToken();
|
|
||||||
String query = request.getEndpoint().getQuery();
|
|
||||||
request = filter.filter(request);
|
|
||||||
assertEquals(request.getEndpoint().getQuery(), query == null ? "sessionToken=" + token : query + "&sessionToken="
|
|
||||||
+ token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testUpdatesOnlyOncePerSecond() throws NoSuchMethodException, InterruptedException {
|
|
||||||
String token = filter.getSessionToken();
|
|
||||||
for (int i = 0; i < 10; i++)
|
|
||||||
filter.updateIfTimeOut();
|
|
||||||
assert token.equals(filter.getSessionToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFilters(HttpRequest request) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private AddSessionTokenToRequest filter;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
@Override
|
|
||||||
protected void setupFactory() throws IOException {
|
|
||||||
super.setupFactory();
|
|
||||||
filter = injector.getInstance(AddSessionTokenToRequest.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>> createTypeLiteral() {
|
|
||||||
return new TypeLiteral<RestAnnotationProcessor<SDNAsyncClient>>() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Module createModule() {
|
|
||||||
return new TestSDNRestClientModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresHttp
|
|
||||||
@ConfiguresRestClient
|
|
||||||
static class TestSDNRestClientModule extends SDNRestClientModule {
|
|
||||||
@Override
|
|
||||||
public void configure() {
|
|
||||||
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
|
|
||||||
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,130 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.filters;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNAsyncClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SDNClient;
|
|
||||||
import org.jclouds.nirvanix.sdn.SessionToken;
|
|
||||||
import org.jclouds.nirvanix.sdn.config.SDNRestClientModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.reference.SDNConstants;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
|
||||||
import org.jclouds.rest.RestContextFactory;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
import com.google.inject.name.Names;
|
|
||||||
|
|
||||||
@Test(groups = "unit", singleThreaded = true, testName = "sdn.InsertUserContextIntoPathTest")
|
|
||||||
// sequential as easymock isn't threadsafe
|
|
||||||
public class InsertUserContextIntoPathTest extends RestClientTest<TestService> {
|
|
||||||
|
|
||||||
private Method method;
|
|
||||||
|
|
||||||
public void testRequestInvalid() {
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
|
|
||||||
request = filter.filter(request);
|
|
||||||
request = filter.filter(request);
|
|
||||||
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRequestNoSession() {
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("https://host/path"));
|
|
||||||
request = filter.filter(request);
|
|
||||||
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRequestAlreadyHasSession() {
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("https://host/sessiontoken/appname/username/path"));
|
|
||||||
request = filter.filter(request);
|
|
||||||
assertEquals(request.getEndpoint().getPath(), "/sessiontoken/appname/username/path");
|
|
||||||
assertEquals(request.getEndpoint().getHost(), "host");
|
|
||||||
}
|
|
||||||
|
|
||||||
private InsertUserContextIntoPath filter;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
@Override
|
|
||||||
protected void setupFactory() throws IOException {
|
|
||||||
super.setupFactory();
|
|
||||||
filter = injector.getInstance(InsertUserContextIntoPath.class);
|
|
||||||
try {
|
|
||||||
method = TestService.class.getMethod("foo", URI.class);
|
|
||||||
} catch (Exception e) {
|
|
||||||
Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TypeLiteral<RestAnnotationProcessor<TestService>> createTypeLiteral() {
|
|
||||||
return new TypeLiteral<RestAnnotationProcessor<TestService>>() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Module createModule() {
|
|
||||||
return new TestSDNRestClientModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresHttp
|
|
||||||
@ConfiguresRestClient
|
|
||||||
static class TestSDNRestClientModule extends SDNRestClientModule {
|
|
||||||
@Override
|
|
||||||
public void configure() {
|
|
||||||
bind(String.class).annotatedWith(SessionToken.class).toInstance("sessiontoken");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPKEY)).toInstance("appKey");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_APPNAME)).toInstance("appname");
|
|
||||||
bind(String.class).annotatedWith(Names.named(SDNConstants.PROPERTY_SDN_USERNAME)).toInstance("username");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestContextSpec<SDNClient, SDNAsyncClient> createContextSpec() {
|
|
||||||
return new RestContextFactory().createContextSpec("sdn", "user", "password", new Properties());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFilters(HttpRequest request) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TestService {
|
|
||||||
@POST
|
|
||||||
public void foo(@EndpointParam URI endpoint);
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code ParseMetadataFromJsonResponse}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.ParseMetadataFromJsonResponseTest")
|
|
||||||
public class ParseMetadataFromJsonResponseTest {
|
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
|
||||||
|
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
|
||||||
InputStream is = getClass().getResourceAsStream("/metadata.json");
|
|
||||||
|
|
||||||
ParseMetadataFromJsonResponse parser = i.getInstance(ParseMetadataFromJsonResponse.class);
|
|
||||||
Map<String, String> response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
|
||||||
assertEquals(response, ImmutableMap.of("MD5", "IGPBYI1uC6+AJJxC4r5YBA==", "test", "1"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code ParseSessionTokenFromJsonResponse}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.ParseSessionTokenFromJsonResponseTest")
|
|
||||||
public class ParseSessionTokenFromJsonResponseTest {
|
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
|
||||||
|
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
|
||||||
InputStream is = getClass().getResourceAsStream("/login.json");
|
|
||||||
|
|
||||||
ParseSessionTokenFromJsonResponse parser = i.getInstance(ParseSessionTokenFromJsonResponse.class);
|
|
||||||
String response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
|
||||||
assertEquals(response, "e4b08449-4501-4b7a-af6a-d4e1e1bd7919");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.nirvanix.sdn.functions;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.io.Payloads;
|
|
||||||
import org.jclouds.json.config.GsonModule;
|
|
||||||
import org.jclouds.nirvanix.sdn.domain.UploadInfo;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.inject.Guice;
|
|
||||||
import com.google.inject.Injector;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code ParseUploadInfoFromJsonResponse}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "sdn.ParseUploadInfoFromJsonResponse")
|
|
||||||
public class ParseUploadInfoFromJsonResponseTest {
|
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new GsonModule());
|
|
||||||
|
|
||||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
|
||||||
InputStream is = getClass().getResourceAsStream("/authtoken.json");
|
|
||||||
|
|
||||||
ParseUploadInfoFromJsonResponse parser = i.getInstance(ParseUploadInfoFromJsonResponse.class);
|
|
||||||
UploadInfo response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));
|
|
||||||
assertEquals(response.getHost(), URI.create("https://node1.nirvanix.com"));
|
|
||||||
assertEquals(response.getToken(), "siR-ALYd~BEcJ8GR2tE~oX3SEHO8~2WXKT5xjFk~YLS5OvJyHI21TN34rQ");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
{"ResponseCode":0,"GetStorageNode":{"UploadHost":"node1.nirvanix.com","UploadToken":"siR-ALYd~BEcJ8GR2tE~oX3SEHO8~2WXKT5xjFk~YLS5OvJyHI21TN34rQ"}}
|
|
|
@ -1,90 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
For more configuration infromation and examples see the Apache Log4j
|
|
||||||
website: http://logging.apache.org/log4j/
|
|
||||||
-->
|
|
||||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
|
|
||||||
debug="false">
|
|
||||||
|
|
||||||
<!-- A time/date based rolling appender -->
|
|
||||||
<appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
|
|
||||||
<param name="File" value="target/test-data/jclouds-wire.log" />
|
|
||||||
<param name="Append" value="true" />
|
|
||||||
|
|
||||||
<!-- Rollover at midnight each day -->
|
|
||||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
|
||||||
|
|
||||||
<param name="Threshold" value="TRACE" />
|
|
||||||
|
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
|
||||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
|
||||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
|
||||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
|
||||||
%m%n"/>
|
|
||||||
-->
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- A time/date based rolling appender -->
|
|
||||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
|
||||||
<param name="File" value="target/test-data/jclouds.log" />
|
|
||||||
<param name="Append" value="true" />
|
|
||||||
|
|
||||||
<!-- Rollover at midnight each day -->
|
|
||||||
<param name="DatePattern" value="'.'yyyy-MM-dd" />
|
|
||||||
|
|
||||||
<param name="Threshold" value="TRACE" />
|
|
||||||
|
|
||||||
<layout class="org.apache.log4j.PatternLayout">
|
|
||||||
<!-- The default pattern: Date Priority [Category] Message\n -->
|
|
||||||
<param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
|
|
||||||
<param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x)
|
|
||||||
%m%n"/>
|
|
||||||
-->
|
|
||||||
</layout>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
|
|
||||||
<appender-ref ref="FILE" />
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
|
|
||||||
<appender-ref ref="WIREFILE" />
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<!-- ================ -->
|
|
||||||
<!-- Limit categories -->
|
|
||||||
<!-- ================ -->
|
|
||||||
|
|
||||||
<category name="org.jclouds">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNC" />
|
|
||||||
</category>
|
|
||||||
|
|
||||||
<category name="jclouds.headers">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNCWIRE" />
|
|
||||||
</category>
|
|
||||||
|
|
||||||
<category name="jclouds.wire">
|
|
||||||
<priority value="DEBUG" />
|
|
||||||
<appender-ref ref="ASYNCWIRE" />
|
|
||||||
</category>
|
|
||||||
|
|
||||||
<!-- ======================= -->
|
|
||||||
<!-- Setup the Root category -->
|
|
||||||
<!-- ======================= -->
|
|
||||||
|
|
||||||
<root>
|
|
||||||
<priority value="WARN" />
|
|
||||||
</root>
|
|
||||||
|
|
||||||
</log4j:configuration>
|
|
|
@ -1 +0,0 @@
|
||||||
{"ResponseCode":0,"SessionToken":"e4b08449-4501-4b7a-af6a-d4e1e1bd7919"}
|
|
|
@ -1 +0,0 @@
|
||||||
{"ResponseCode":0,"Metadata":[{"Type":"MD5","Value":"IGPBYI1uC6+AJJxC4r5YBA=="},{"Type":"test","Value":"1"}]}
|
|
|
@ -1,25 +0,0 @@
|
||||||
====
|
|
||||||
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.
|
|
||||||
====
|
|
||||||
|
|
||||||
#
|
|
||||||
# The jclouds provider for Mezeo Cloud Storage (http://www.mezeo.com/the-platform).
|
|
||||||
#
|
|
||||||
# TODO: Implementation status.
|
|
||||||
# TODO: Supported features.
|
|
||||||
# TODO: Usage example.
|
|
|
@ -1,126 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<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/maven-v4_0_0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-project</artifactId>
|
|
||||||
<version>1.7.0-SNAPSHOT</version>
|
|
||||||
<relativePath>../../project/pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
<groupId>org.jclouds.api</groupId>
|
|
||||||
<artifactId>pcs</artifactId>
|
|
||||||
<name>jclouds mezeo cloud storage platform core</name>
|
|
||||||
<description>jclouds Core components to access mezeo pcs2</description>
|
|
||||||
<packaging>bundle</packaging>
|
|
||||||
|
|
||||||
<!-- bootstrapping: need to fetch the project POM -->
|
|
||||||
<repositories>
|
|
||||||
<repository>
|
|
||||||
<id>jclouds-sona-snapshots-nexus</id>
|
|
||||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<test.pcs.endpoint>FIXME</test.pcs.endpoint>
|
|
||||||
<test.pcs.api-version>2</test.pcs.api-version>
|
|
||||||
<test.pcs.build-version></test.pcs.build-version>
|
|
||||||
<test.pcs.identity>FIXME</test.pcs.identity>
|
|
||||||
<test.pcs.credential>FIXME</test.pcs.credential>
|
|
||||||
|
|
||||||
<jclouds.osgi.export>org.jclouds.mezeo.pcs*;version="${project.version}"</jclouds.osgi.export>
|
|
||||||
<jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-blobstore</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-core</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds</groupId>
|
|
||||||
<artifactId>jclouds-blobstore</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<type>test-jar</type>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jclouds.driver</groupId>
|
|
||||||
<artifactId>jclouds-log4j</artifactId>
|
|
||||||
<version>${project.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<profiles>
|
|
||||||
<profile>
|
|
||||||
<id>live</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>integration</id>
|
|
||||||
<phase>integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>test</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<test.pcs.endpoint>${test.pcs.endpoint}</test.pcs.endpoint>
|
|
||||||
<test.pcs.api-version>${test.pcs.api-version}</test.pcs.api-version>
|
|
||||||
<test.pcs.build-version>${test.pcs.build-version}</test.pcs.build-version>
|
|
||||||
<test.pcs.identity>${test.pcs.identity}</test.pcs.identity>
|
|
||||||
<test.pcs.credential>${test.pcs.credential}</test.pcs.credential>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,179 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.mezeo.pcs.binders.BindContainerNameToXmlPayload;
|
|
||||||
import org.jclouds.mezeo.pcs.binders.BindFileInfoToXmlPayload;
|
|
||||||
import org.jclouds.mezeo.pcs.binders.BindPCSFileToMultipartForm;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ContainerList;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfoWithMetadata;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.RootContainer;
|
|
||||||
import org.jclouds.mezeo.pcs.functions.AddMetadataItemIntoMap;
|
|
||||||
import org.jclouds.mezeo.pcs.options.PutBlockOptions;
|
|
||||||
import org.jclouds.mezeo.pcs.xml.ContainerHandler;
|
|
||||||
import org.jclouds.mezeo.pcs.xml.FileHandler;
|
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
|
||||||
import org.jclouds.rest.annotations.Endpoint;
|
|
||||||
import org.jclouds.rest.annotations.EndpointParam;
|
|
||||||
import org.jclouds.rest.annotations.ExceptionParser;
|
|
||||||
import org.jclouds.rest.annotations.Headers;
|
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
|
||||||
import org.jclouds.rest.annotations.SkipEncoding;
|
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
|
||||||
import org.jclouds.rest.binders.BindToStringPayload;
|
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides asynchronous access to Mezeo PCS via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @see PCSClient
|
|
||||||
* @see <a href=
|
|
||||||
* "http://developer.mezeo.com/mezeo-developer-center/documentation/howto-using-curl-to-access-api"
|
|
||||||
* />
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@SkipEncoding('/')
|
|
||||||
@RequestFilters(BasicAuthentication.class)
|
|
||||||
public interface PCSAsyncClient {
|
|
||||||
PCSFile newFile();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#list()
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@XMLResponseParser(ContainerHandler.class)
|
|
||||||
@Headers(keys = "X-Cloud-Depth", values = "2")
|
|
||||||
@Endpoint(RootContainer.class)
|
|
||||||
ListenableFuture<? extends ContainerList> list();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#list(URI)
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@XMLResponseParser(ContainerHandler.class)
|
|
||||||
@Headers(keys = "X-Cloud-Depth", values = "2")
|
|
||||||
ListenableFuture<? extends ContainerList> list(@EndpointParam URI container);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#createContainer
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("/contents")
|
|
||||||
@Endpoint(RootContainer.class)
|
|
||||||
@Produces("application/vnd.csp.container-info+xml")
|
|
||||||
ListenableFuture<URI> createContainer(@BinderParam(BindContainerNameToXmlPayload.class) String container);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#createContainer
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("/contents")
|
|
||||||
ListenableFuture<URI> createContainer(@EndpointParam URI parent,
|
|
||||||
@BinderParam(BindContainerNameToXmlPayload.class) String container);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#deleteContainer
|
|
||||||
*/
|
|
||||||
@DELETE
|
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
|
||||||
ListenableFuture<Void> deleteContainer(@EndpointParam URI container);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#uploadFile
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("/contents")
|
|
||||||
ListenableFuture<URI> uploadFile(@EndpointParam URI container,
|
|
||||||
@BinderParam(BindPCSFileToMultipartForm.class) PCSFile object);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#createFile
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
@Path("/contents")
|
|
||||||
ListenableFuture<URI> createFile(@EndpointParam URI container,
|
|
||||||
@BinderParam(BindFileInfoToXmlPayload.class) PCSFile object);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#uploadBlock
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path("/content")
|
|
||||||
ListenableFuture<Void> uploadBlock(@EndpointParam URI file, PCSFile object, PutBlockOptions... options);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#deleteFile
|
|
||||||
*/
|
|
||||||
@DELETE
|
|
||||||
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
|
|
||||||
ListenableFuture<Void> deleteFile(@EndpointParam URI file);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#downloadFile
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@ExceptionParser(ReturnNullOnKeyNotFound.class)
|
|
||||||
@Path("/content")
|
|
||||||
ListenableFuture<InputStream> downloadFile(@EndpointParam URI file);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#getFileInfo
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@ExceptionParser(ReturnNullOnKeyNotFound.class)
|
|
||||||
@XMLResponseParser(FileHandler.class)
|
|
||||||
@Headers(keys = "X-Cloud-Depth", values = "2")
|
|
||||||
ListenableFuture<FileInfoWithMetadata> getFileInfo(@EndpointParam URI file);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#putMetadataItem
|
|
||||||
*/
|
|
||||||
@PUT
|
|
||||||
@Path("/metadata/{key}")
|
|
||||||
ListenableFuture<Void> putMetadataItem(@EndpointParam URI resource, @PathParam("key") String key,
|
|
||||||
@BinderParam(BindToStringPayload.class) String value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see PCSAsyncClient#addMetadataItemToMap
|
|
||||||
*/
|
|
||||||
@GET
|
|
||||||
@ResponseParser(AddMetadataItemIntoMap.class)
|
|
||||||
@Path("/metadata/{key}")
|
|
||||||
ListenableFuture<Void> addMetadataItemToMap(@EndpointParam URI resource, @PathParam("key") String key,
|
|
||||||
Map<String, String> map);
|
|
||||||
}
|
|
|
@ -1,70 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ContainerList;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfoWithMetadata;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.mezeo.pcs.options.PutBlockOptions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides access to Mezeo PCS via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @see <a href=
|
|
||||||
* "http://developer.mezeo.com/mezeo-developer-center/documentation/howto-using-curl-to-access-api"
|
|
||||||
* />
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
|
||||||
public interface PCSClient {
|
|
||||||
PCSFile newFile();
|
|
||||||
|
|
||||||
ContainerList list();
|
|
||||||
|
|
||||||
ContainerList list(URI container);
|
|
||||||
|
|
||||||
URI createContainer(String container);
|
|
||||||
|
|
||||||
URI createContainer(URI parent, String container);
|
|
||||||
|
|
||||||
void deleteContainer(URI container);
|
|
||||||
|
|
||||||
URI uploadFile(URI container, PCSFile object);
|
|
||||||
|
|
||||||
URI createFile(URI container, PCSFile object);
|
|
||||||
|
|
||||||
void uploadBlock(URI file, PCSFile object, PutBlockOptions... options);
|
|
||||||
|
|
||||||
void deleteFile(URI file);
|
|
||||||
|
|
||||||
InputStream downloadFile(URI file);
|
|
||||||
|
|
||||||
FileInfoWithMetadata getFileInfo(URI file);
|
|
||||||
|
|
||||||
void putMetadataItem(URI resource, String key, String value);
|
|
||||||
|
|
||||||
void addMetadataItemToMap(URI resource, String key, Map<String, String> map);
|
|
||||||
}
|
|
|
@ -1,76 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Contacts;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Metacontainers;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Projects;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Recyclebin;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.RootContainer;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Shares;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Tags;
|
|
||||||
import org.jclouds.mezeo.pcs.xml.CloudXlinkHandler;
|
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
|
||||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides URIs to PCS services via their REST API.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@RequestFilters(BasicAuthentication.class)
|
|
||||||
public interface PCSCloudAsyncClient {
|
|
||||||
|
|
||||||
public interface Response {
|
|
||||||
@RootContainer
|
|
||||||
URI getRootContainerUrl();
|
|
||||||
|
|
||||||
@Contacts
|
|
||||||
URI getContactsUrl();
|
|
||||||
|
|
||||||
@Shares
|
|
||||||
URI getSharesUrl();
|
|
||||||
|
|
||||||
@Projects
|
|
||||||
URI getProjectsUrl();
|
|
||||||
|
|
||||||
@Metacontainers
|
|
||||||
URI getMetacontainersUrl();
|
|
||||||
|
|
||||||
@Recyclebin
|
|
||||||
URI getRecyclebinUrl();
|
|
||||||
|
|
||||||
@Tags
|
|
||||||
URI getTagsUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@GET
|
|
||||||
@XMLResponseParser(CloudXlinkHandler.class)
|
|
||||||
@Path("/v{jclouds.api-version}")
|
|
||||||
ListenableFuture<Response> authenticate();
|
|
||||||
}
|
|
|
@ -1,42 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.config.PCSRestClientModule;
|
|
||||||
import org.jclouds.rest.RestContextBuilder;
|
|
||||||
|
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PCSContextBuilder extends RestContextBuilder<PCSClient, PCSAsyncClient> {
|
|
||||||
|
|
||||||
public PCSContextBuilder(Properties props) {
|
|
||||||
super(PCSClient.class, PCSAsyncClient.class, props);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addClientModule(List<Module> modules) {
|
|
||||||
modules.add(new PCSRestClientModule());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.PropertiesBuilder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds properties used in PCS Connections
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PCSPropertiesBuilder extends PropertiesBuilder {
|
|
||||||
@Override
|
|
||||||
protected Properties defaultProperties() {
|
|
||||||
Properties properties = super.defaultProperties();
|
|
||||||
properties.setProperty(PROPERTY_API_VERSION, "2");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PCSPropertiesBuilder(Properties properties) {
|
|
||||||
super(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.binders;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.rest.Binder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BindContainerNameToXmlPayload implements Binder {
|
|
||||||
@Override
|
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
|
||||||
String container = String.format("<container><name>%s</name></container>", input);
|
|
||||||
request.setPayload(container);
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.binders;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.utils.ModifyRequest;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.rest.Binder;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BindFileInfoToXmlPayload implements Binder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
|
||||||
PCSFile blob = (PCSFile) input;
|
|
||||||
String file = String.format("<file><name>%s</name><mime_type>%s</mime_type><public>false</public></file>",
|
|
||||||
new File(blob.getMetadata().getName()).getName(), blob.getMetadata().getMimeType());
|
|
||||||
request.setPayload(file);
|
|
||||||
return ModifyRequest.replaceHeaders(request, ImmutableMultimap.<String, String> of(HttpHeaders.CONTENT_LENGTH,
|
|
||||||
file.getBytes().length + "", HttpHeaders.CONTENT_TYPE, "application/vnd.csp.file-info+xml"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,52 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.binders;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.binders.BindBlobToMultipartForm;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.mezeo.pcs.blobstore.functions.PCSFileToBlob;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.rest.Binder;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class BindPCSFileToMultipartForm implements Binder {
|
|
||||||
private final BindBlobToMultipartForm blobBinder;
|
|
||||||
private final PCSFileToBlob file2Blob;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public BindPCSFileToMultipartForm(PCSFileToBlob file2Blob, BindBlobToMultipartForm blobBinder) {
|
|
||||||
this.blobBinder = blobBinder;
|
|
||||||
this.file2Blob = file2Blob;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
|
||||||
PCSFile file = (PCSFile) input;
|
|
||||||
checkNotNull(file.getPayload().getContentMetadata().getContentLength(), "contentLength");
|
|
||||||
checkArgument(file.getPayload().getContentMetadata().getContentLength() <= 2l * 1024 * 1024 * 1024,
|
|
||||||
"maximum size for POST request is 2GB");
|
|
||||||
return blobBinder.bindToRequest(request, file2Blob.apply(file));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.blobstore.functions;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.BlobMetadata;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.MutableFileInfo;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.MutableFileInfoImpl;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BlobToFileInfo implements Function<BlobMetadata, MutableFileInfo> {
|
|
||||||
@Override
|
|
||||||
public MutableFileInfo apply(BlobMetadata base) {
|
|
||||||
MutableFileInfo to = new MutableFileInfoImpl();
|
|
||||||
to.setUrl(base.getUri());
|
|
||||||
to.setMimeType(base.getContentMetadata().getContentType());
|
|
||||||
to.setName(base.getName());
|
|
||||||
to.setModified(base.getLastModified());
|
|
||||||
if (base.getContentMetadata().getContentLength() != null)
|
|
||||||
to.setBytes(base.getContentMetadata().getContentLength());
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,49 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.blobstore.functions;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class BlobToPCSFile implements Function<Blob, PCSFile> {
|
|
||||||
private final BlobToFileInfo blob2ObjectMd;
|
|
||||||
private final PCSFile.Factory objectProvider;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
BlobToPCSFile(BlobToFileInfo blob2ObjectMd, PCSFile.Factory objectProvider) {
|
|
||||||
this.blob2ObjectMd = blob2ObjectMd;
|
|
||||||
this.objectProvider = objectProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PCSFile apply(Blob from) {
|
|
||||||
PCSFile object = objectProvider.create(blob2ObjectMd.apply(from.getMetadata()));
|
|
||||||
object.setPayload(from.getPayload());
|
|
||||||
object.setAllHeaders(from.getAllHeaders());
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.blobstore.functions;
|
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.MutableBlobMetadata;
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfo;
|
|
||||||
import org.jclouds.util.Strings2;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class FileInfoToBlobMetadata implements Function<FileInfo, MutableBlobMetadata> {
|
|
||||||
public static final Pattern OBJECTS_PATTERN = Pattern.compile(".*objects/");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MutableBlobMetadata apply(FileInfo from) {
|
|
||||||
MutableBlobMetadata to = new MutableBlobMetadataImpl();
|
|
||||||
if (from.getUrl() != null) {
|
|
||||||
to.setId(Strings2.replaceAll(from.getUrl().getPath(), OBJECTS_PATTERN, ""));
|
|
||||||
}
|
|
||||||
to.setUri(from.getUrl());
|
|
||||||
to.setName(from.getName());
|
|
||||||
if (from.getMimeType() != null)
|
|
||||||
to.getContentMetadata().setContentType(from.getMimeType());
|
|
||||||
if (from.getModified() != null)
|
|
||||||
to.setLastModified(from.getModified());
|
|
||||||
if (from.getBytes() != null)
|
|
||||||
to.getContentMetadata().setContentLength(from.getBytes());
|
|
||||||
to.setType(StorageType.BLOB);
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.blobstore.functions;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class PCSFileToBlob implements Function<PCSFile, Blob> {
|
|
||||||
private final Blob.Factory blobFactory;
|
|
||||||
private final FileInfoToBlobMetadata info2BlobMd;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
PCSFileToBlob(Factory blobFactory, FileInfoToBlobMetadata info2BlobMd) {
|
|
||||||
this.blobFactory = blobFactory;
|
|
||||||
this.info2BlobMd = info2BlobMd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blob apply(PCSFile from) {
|
|
||||||
Blob blob = blobFactory.create(info2BlobMd.apply(from.getMetadata()));
|
|
||||||
blob.setPayload(from.getPayload());
|
|
||||||
blob.setAllHeaders(from.getAllHeaders());
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.config;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Provider;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.config.BlobStoreObjectModule;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.MutableFileInfo;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.PCSFileImpl;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Scopes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the domain object mappings needed for all PCS implementations
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PCSObjectModule extends AbstractModule {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* explicit factories are created here as it has been shown that Assisted Inject is extremely
|
|
||||||
* inefficient. http://code.google.com/p/google-guice/issues/detail?id=435
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
// for adapters
|
|
||||||
install(new BlobStoreObjectModule());
|
|
||||||
bind(PCSFile.Factory.class).to(PCSFileFactory.class).in(Scopes.SINGLETON);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PCSFileFactory implements PCSFile.Factory {
|
|
||||||
@Inject
|
|
||||||
Provider<MutableFileInfo> metadataProvider;
|
|
||||||
|
|
||||||
public PCSFile create(MutableFileInfo metadata) {
|
|
||||||
return new PCSFileImpl(metadata != null ? metadata : metadataProvider.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
PCSFile providePCSFile(PCSFile.Factory factory) {
|
|
||||||
return factory.create(null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,139 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.config;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
|
||||||
|
|
||||||
import javax.inject.Named;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.http.annotation.ClientError;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSAsyncClient;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSClient;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSCloudAsyncClient;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSCloudAsyncClient.Response;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Contacts;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Metacontainers;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Projects;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Recyclebin;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.RootContainer;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Shares;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.Tags;
|
|
||||||
import org.jclouds.mezeo.pcs.endpoints.WebDAV;
|
|
||||||
import org.jclouds.mezeo.pcs.handlers.PCSClientErrorRetryHandler;
|
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.config.RestClientModule;
|
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the PCSCloudModule authentication service connection.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@RequiresHttp
|
|
||||||
@ConfiguresRestClient
|
|
||||||
public class PCSRestClientModule extends RestClientModule<PCSClient, PCSAsyncClient> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
install(new PCSObjectModule());
|
|
||||||
super.configure();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PCSRestClientModule() {
|
|
||||||
super(PCSClient.class, PCSAsyncClient.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
protected Response provideCloudResponse(AsyncClientFactory factory) throws InterruptedException, ExecutionException,
|
|
||||||
TimeoutException {
|
|
||||||
return factory.create(PCSCloudAsyncClient.class).authenticate().get(10, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@WebDAV
|
|
||||||
protected URI provideWebDAVURI(@Named(Constants.PROPERTY_ENDPOINT) String endpoint) {
|
|
||||||
return URI.create(endpoint + "/dav");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Contacts
|
|
||||||
protected URI provideContactsUrl(Response response) {
|
|
||||||
return response.getContactsUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Metacontainers
|
|
||||||
protected URI provideMetacontainersUrl(Response response) {
|
|
||||||
return response.getMetacontainersUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Projects
|
|
||||||
protected URI provideProjectsUrl(Response response) {
|
|
||||||
return response.getProjectsUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Recyclebin
|
|
||||||
protected URI provideRecyclebinUrl(Response response) {
|
|
||||||
return response.getRecyclebinUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@RootContainer
|
|
||||||
protected URI provideRootContainerUrl(Response response) {
|
|
||||||
return response.getRootContainerUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Shares
|
|
||||||
protected URI provideSharesUrl(Response response) {
|
|
||||||
return response.getSharesUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@Singleton
|
|
||||||
@Tags
|
|
||||||
protected URI provideTagsUrl(Response response) {
|
|
||||||
return response.getTagsUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void bindRetryHandlers() {
|
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(PCSClientErrorRetryHandler.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.ContainerInfoImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(ContainerInfoImpl.class)
|
|
||||||
public interface ContainerInfo extends ResourceInfo {
|
|
||||||
|
|
||||||
URI getContents();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.ContainerListImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(ContainerListImpl.class)
|
|
||||||
public interface ContainerList extends ResourceInfo, SortedSet<ResourceInfo> {
|
|
||||||
Map<String, URI> getMetadataItems();
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.FileInfoImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(FileInfoImpl.class)
|
|
||||||
public interface FileInfo extends ResourceInfo {
|
|
||||||
|
|
||||||
Boolean isPublic();
|
|
||||||
|
|
||||||
String getMimeType();
|
|
||||||
|
|
||||||
URI getContent();
|
|
||||||
|
|
||||||
URI getPermissions();
|
|
||||||
|
|
||||||
URI getThumbnail();
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.FileInfoWithMetadataImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(FileInfoWithMetadataImpl.class)
|
|
||||||
public interface FileInfoWithMetadata extends FileInfo {
|
|
||||||
Map<String, URI> getMetadataItems();
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.MutableFileInfoImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(MutableFileInfoImpl.class)
|
|
||||||
public interface MutableFileInfo extends FileInfo, MutableResourceInfo {
|
|
||||||
|
|
||||||
void setPublic(Boolean isPublic);
|
|
||||||
|
|
||||||
void setMimeType(String value);
|
|
||||||
|
|
||||||
void setContent(URI value);
|
|
||||||
|
|
||||||
void setPermissions(URI value);
|
|
||||||
|
|
||||||
void setThumbnail(URI value);
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.MutableResourceInfoImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(MutableResourceInfoImpl.class)
|
|
||||||
public interface MutableResourceInfo extends ResourceInfo {
|
|
||||||
void setType(StorageType value);
|
|
||||||
|
|
||||||
void setUrl(URI value);
|
|
||||||
|
|
||||||
void setName(String value);
|
|
||||||
|
|
||||||
void setCreated(Date value);
|
|
||||||
|
|
||||||
void setInProject(Boolean value);
|
|
||||||
|
|
||||||
void setModified(Date value);
|
|
||||||
|
|
||||||
void setOwner(String value);
|
|
||||||
|
|
||||||
void setVersion(Integer value);
|
|
||||||
|
|
||||||
void setShared(Boolean value);
|
|
||||||
|
|
||||||
void setAccessed(Date value);
|
|
||||||
|
|
||||||
void setBytes(Long value);
|
|
||||||
|
|
||||||
void setMetadata(URI value);
|
|
||||||
|
|
||||||
void setParent(URI value);
|
|
||||||
|
|
||||||
void setTags(URI value);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.jclouds.io.PayloadEnclosing;
|
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public interface PCSFile extends PayloadEnclosing, Comparable<PCSFile> {
|
|
||||||
public interface Factory {
|
|
||||||
PCSFile create(@Nullable MutableFileInfo metadata);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return System and User metadata relevant to this object.
|
|
||||||
*/
|
|
||||||
MutableFileInfo getMetadata();
|
|
||||||
|
|
||||||
Multimap<String, String> getAllHeaders();
|
|
||||||
|
|
||||||
void setAllHeaders(Multimap<String, String> allHeaders);
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.ResourceInfoImpl;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@ImplementedBy(ResourceInfoImpl.class)
|
|
||||||
public interface ResourceInfo extends Comparable<ResourceInfo> {
|
|
||||||
StorageType getType();
|
|
||||||
|
|
||||||
URI getUrl();
|
|
||||||
|
|
||||||
String getName();
|
|
||||||
|
|
||||||
Date getCreated();
|
|
||||||
|
|
||||||
Boolean isInProject();
|
|
||||||
|
|
||||||
Date getModified();
|
|
||||||
|
|
||||||
String getOwner();
|
|
||||||
|
|
||||||
Integer getVersion();
|
|
||||||
|
|
||||||
Boolean isShared();
|
|
||||||
|
|
||||||
Date getAccessed();
|
|
||||||
|
|
||||||
Long getBytes();
|
|
||||||
|
|
||||||
URI getMetadata();
|
|
||||||
|
|
||||||
URI getParent();
|
|
||||||
|
|
||||||
URI getTags();
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ContainerInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ContainerInfoImpl extends ResourceInfoImpl implements ContainerInfo {
|
|
||||||
private final URI contents;
|
|
||||||
|
|
||||||
public ContainerInfoImpl(URI url, String name, Date created, boolean inProject, Date modified,
|
|
||||||
String owner, int version, boolean shared, Date accessed, long bytes, URI contents,
|
|
||||||
URI tags, URI metadata, URI parent) {
|
|
||||||
super(StorageType.FOLDER, url, name, created, inProject, modified, owner, version, shared,
|
|
||||||
accessed, bytes, tags, metadata, parent);
|
|
||||||
this.contents = contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getContents() {
|
|
||||||
return contents;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = prime * result + ((contents == null) ? 0 : contents.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (!super.equals(obj))
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
ContainerInfoImpl other = (ContainerInfoImpl) obj;
|
|
||||||
if (contents == null) {
|
|
||||||
if (other.contents != null)
|
|
||||||
return false;
|
|
||||||
} else if (!contents.equals(other.contents))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ContainerList;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ResourceInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ContainerListImpl extends TreeSet<ResourceInfo> implements ContainerList {
|
|
||||||
|
|
||||||
private final ResourceInfo info;
|
|
||||||
private final Map<String, URI> metadataItems;
|
|
||||||
|
|
||||||
public ContainerListImpl(URI url, String name, Date created, boolean inProject, Date modified,
|
|
||||||
String owner, int version, boolean shared, Date accessed, long bytes,
|
|
||||||
SortedSet<? extends ResourceInfo> contents, URI tags, URI metadata,
|
|
||||||
Map<String, URI> metadataItems, URI parent) {
|
|
||||||
this.info = new ResourceInfoImpl(StorageType.FOLDER, url, name, created, inProject,
|
|
||||||
modified, owner, version, shared, accessed, bytes, tags, metadata, parent);
|
|
||||||
addAll(contents);
|
|
||||||
this.metadataItems = metadataItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, URI> getMetadataItems() {
|
|
||||||
return metadataItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getAccessed() {
|
|
||||||
return info.getAccessed();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getBytes() {
|
|
||||||
return info.getBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return info.getCreated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getMetadata() {
|
|
||||||
return info.getMetadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getModified() {
|
|
||||||
return info.getModified();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return info.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
return info.getOwner();
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getParent() {
|
|
||||||
return info.getParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getTags() {
|
|
||||||
return info.getTags();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageType getType() {
|
|
||||||
return info.getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getUrl() {
|
|
||||||
return info.getUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getVersion() {
|
|
||||||
return info.getVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isInProject() {
|
|
||||||
return info.isInProject();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isShared() {
|
|
||||||
return info.isShared();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(ResourceInfo o) {
|
|
||||||
return info.compareTo(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FileInfoImpl extends ResourceInfoImpl implements FileInfo {
|
|
||||||
|
|
||||||
private final Boolean isPublic;
|
|
||||||
private final String mimeType;
|
|
||||||
private final URI content;
|
|
||||||
private final URI permissions;
|
|
||||||
private final URI thumbnail;
|
|
||||||
|
|
||||||
public FileInfoImpl(URI url, String name, Date created, boolean inProject,
|
|
||||||
Date modified,
|
|
||||||
String owner, int version, boolean shared, Date accessed,
|
|
||||||
boolean isPublic, String mimeType, long bytes, URI content, URI parent,
|
|
||||||
URI permissions, URI tags, URI metadata, URI thumbnail) {
|
|
||||||
super(StorageType.BLOB, url, name, created, inProject, modified, owner, version, shared,
|
|
||||||
accessed, bytes, tags, metadata, parent);
|
|
||||||
this.isPublic = isPublic;
|
|
||||||
this.mimeType = mimeType;
|
|
||||||
this.content=content;
|
|
||||||
this.permissions = permissions;
|
|
||||||
this.thumbnail = thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMimeType() {
|
|
||||||
return mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getPermissions() {
|
|
||||||
return permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getThumbnail() {
|
|
||||||
return thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = prime * result + ((content == null) ? 0 : content.hashCode());
|
|
||||||
result = prime * result + (isPublic ? 1231 : 1237);
|
|
||||||
result = prime * result + ((mimeType == null) ? 0 : mimeType.hashCode());
|
|
||||||
result = prime * result + ((permissions == null) ? 0 : permissions.hashCode());
|
|
||||||
result = prime * result + ((thumbnail == null) ? 0 : thumbnail.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (!super.equals(obj))
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
FileInfoImpl other = (FileInfoImpl) obj;
|
|
||||||
if (content == null) {
|
|
||||||
if (other.content != null)
|
|
||||||
return false;
|
|
||||||
} else if (!content.equals(other.content))
|
|
||||||
return false;
|
|
||||||
if (isPublic != other.isPublic)
|
|
||||||
return false;
|
|
||||||
if (mimeType == null) {
|
|
||||||
if (other.mimeType != null)
|
|
||||||
return false;
|
|
||||||
} else if (!mimeType.equals(other.mimeType))
|
|
||||||
return false;
|
|
||||||
if (permissions == null) {
|
|
||||||
if (other.permissions != null)
|
|
||||||
return false;
|
|
||||||
} else if (!permissions.equals(other.permissions))
|
|
||||||
return false;
|
|
||||||
if (thumbnail == null) {
|
|
||||||
if (other.thumbnail != null)
|
|
||||||
return false;
|
|
||||||
} else if (!thumbnail.equals(other.thumbnail))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfoWithMetadata;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FileInfoWithMetadataImpl extends FileInfoImpl implements FileInfoWithMetadata {
|
|
||||||
private final Map<String, URI> metadataItems;
|
|
||||||
|
|
||||||
public FileInfoWithMetadataImpl(URI url, String name, Date created, boolean inProject,
|
|
||||||
Date modified, String owner, int version, boolean shared, Date accessed,
|
|
||||||
boolean isPublic, String mimeType, long bytes, URI content, URI parent,
|
|
||||||
URI permissions, URI tags, URI metadata, Map<String, URI> metadataItems, URI thumbnail) {
|
|
||||||
super(url, name, created, inProject, modified, owner, version, shared, accessed, isPublic,
|
|
||||||
mimeType, bytes, content, parent, permissions, tags, metadata, thumbnail);
|
|
||||||
this.metadataItems = metadataItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, URI> getMetadataItems() {
|
|
||||||
return metadataItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = prime * result + ((metadataItems == null) ? 0 : metadataItems.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (!super.equals(obj))
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
FileInfoWithMetadataImpl other = (FileInfoWithMetadataImpl) obj;
|
|
||||||
if (metadataItems == null) {
|
|
||||||
if (other.metadataItems != null)
|
|
||||||
return false;
|
|
||||||
} else if (!metadataItems.equals(other.metadataItems))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.MutableFileInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MutableFileInfoImpl extends MutableResourceInfoImpl implements
|
|
||||||
MutableFileInfo {
|
|
||||||
|
|
||||||
private Boolean isPublic;
|
|
||||||
private String mimeType;
|
|
||||||
private URI content;
|
|
||||||
private URI permissions;
|
|
||||||
private URI thumbnail;
|
|
||||||
|
|
||||||
public MutableFileInfoImpl() {
|
|
||||||
setType(StorageType.BLOB);
|
|
||||||
setMimeType(MediaType.APPLICATION_OCTET_STREAM);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMimeType() {
|
|
||||||
return mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getContent() {
|
|
||||||
return content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getPermissions() {
|
|
||||||
return permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getThumbnail() {
|
|
||||||
return thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPublic(Boolean isPublic) {
|
|
||||||
this.isPublic = isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isPublic() {
|
|
||||||
return isPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMimeType(String mimeType) {
|
|
||||||
this.mimeType = mimeType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setContent(URI content) {
|
|
||||||
this.content = content;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPermissions(URI permissions) {
|
|
||||||
this.permissions = permissions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setThumbnail(URI thumbnail) {
|
|
||||||
this.thumbnail = thumbnail;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = super.hashCode();
|
|
||||||
result = prime * result + ((content == null) ? 0 : content.hashCode());
|
|
||||||
result = prime * result + ((isPublic == null) ? 0 : isPublic.hashCode());
|
|
||||||
result = prime * result + ((mimeType == null) ? 0 : mimeType.hashCode());
|
|
||||||
result = prime * result + ((permissions == null) ? 0 : permissions.hashCode());
|
|
||||||
result = prime * result + ((thumbnail == null) ? 0 : thumbnail.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (!super.equals(obj))
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
MutableFileInfoImpl other = (MutableFileInfoImpl) obj;
|
|
||||||
if (content == null) {
|
|
||||||
if (other.content != null)
|
|
||||||
return false;
|
|
||||||
} else if (!content.equals(other.content))
|
|
||||||
return false;
|
|
||||||
if (isPublic == null) {
|
|
||||||
if (other.isPublic != null)
|
|
||||||
return false;
|
|
||||||
} else if (!isPublic.equals(other.isPublic))
|
|
||||||
return false;
|
|
||||||
if (mimeType == null) {
|
|
||||||
if (other.mimeType != null)
|
|
||||||
return false;
|
|
||||||
} else if (!mimeType.equals(other.mimeType))
|
|
||||||
return false;
|
|
||||||
if (permissions == null) {
|
|
||||||
if (other.permissions != null)
|
|
||||||
return false;
|
|
||||||
} else if (!permissions.equals(other.permissions))
|
|
||||||
return false;
|
|
||||||
if (thumbnail == null) {
|
|
||||||
if (other.thumbnail != null)
|
|
||||||
return false;
|
|
||||||
} else if (!thumbnail.equals(other.thumbnail))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,271 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.MutableResourceInfo;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ResourceInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MutableResourceInfoImpl implements MutableResourceInfo {
|
|
||||||
|
|
||||||
private StorageType type;
|
|
||||||
private URI url;
|
|
||||||
private String name;
|
|
||||||
private Date created;
|
|
||||||
private Boolean inProject;
|
|
||||||
private Date modified;
|
|
||||||
private String owner;
|
|
||||||
private Integer version;
|
|
||||||
private Boolean shared;
|
|
||||||
private Date accessed;
|
|
||||||
private Long bytes;
|
|
||||||
private URI tags;
|
|
||||||
private URI metadata;
|
|
||||||
private URI parent;
|
|
||||||
|
|
||||||
public int compareTo(ResourceInfo o) {
|
|
||||||
if (getName() == null)
|
|
||||||
return -1;
|
|
||||||
return (this == o) ? 0 : getName().compareTo(o.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(StorageType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(URI url) {
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCreated(Date created) {
|
|
||||||
this.created = created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isInProject() {
|
|
||||||
return inProject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInProject(Boolean inProject) {
|
|
||||||
this.inProject = inProject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getModified() {
|
|
||||||
return modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModified(Date modified) {
|
|
||||||
this.modified = modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwner(String owner) {
|
|
||||||
this.owner = owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(Integer version) {
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isShared() {
|
|
||||||
return shared;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShared(Boolean shared) {
|
|
||||||
this.shared = shared;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getAccessed() {
|
|
||||||
return accessed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccessed(Date accessed) {
|
|
||||||
this.accessed = accessed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getBytes() {
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBytes(Long bytes) {
|
|
||||||
this.bytes = bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(URI tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMetadata(URI metadata) {
|
|
||||||
this.metadata = metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParent(URI parent) {
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((accessed == null) ? 0 : accessed.hashCode());
|
|
||||||
result = prime * result + ((bytes == null) ? 0 : bytes.hashCode());
|
|
||||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
|
||||||
result = prime * result + ((inProject == null) ? 0 : inProject.hashCode());
|
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
|
||||||
result = prime * result + ((modified == null) ? 0 : modified.hashCode());
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
|
||||||
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
|
|
||||||
result = prime * result + ((shared == null) ? 0 : shared.hashCode());
|
|
||||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
|
||||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
|
||||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
|
||||||
result = prime * result + ((version == null) ? 0 : version.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
MutableResourceInfoImpl other = (MutableResourceInfoImpl) obj;
|
|
||||||
if (accessed == null) {
|
|
||||||
if (other.accessed != null)
|
|
||||||
return false;
|
|
||||||
} else if (!accessed.equals(other.accessed))
|
|
||||||
return false;
|
|
||||||
if (bytes == null) {
|
|
||||||
if (other.bytes != null)
|
|
||||||
return false;
|
|
||||||
} else if (!bytes.equals(other.bytes))
|
|
||||||
return false;
|
|
||||||
if (created == null) {
|
|
||||||
if (other.created != null)
|
|
||||||
return false;
|
|
||||||
} else if (!created.equals(other.created))
|
|
||||||
return false;
|
|
||||||
if (inProject == null) {
|
|
||||||
if (other.inProject != null)
|
|
||||||
return false;
|
|
||||||
} else if (!inProject.equals(other.inProject))
|
|
||||||
return false;
|
|
||||||
if (metadata == null) {
|
|
||||||
if (other.metadata != null)
|
|
||||||
return false;
|
|
||||||
} else if (!metadata.equals(other.metadata))
|
|
||||||
return false;
|
|
||||||
if (modified == null) {
|
|
||||||
if (other.modified != null)
|
|
||||||
return false;
|
|
||||||
} else if (!modified.equals(other.modified))
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (owner == null) {
|
|
||||||
if (other.owner != null)
|
|
||||||
return false;
|
|
||||||
} else if (!owner.equals(other.owner))
|
|
||||||
return false;
|
|
||||||
if (parent == null) {
|
|
||||||
if (other.parent != null)
|
|
||||||
return false;
|
|
||||||
} else if (!parent.equals(other.parent))
|
|
||||||
return false;
|
|
||||||
if (shared == null) {
|
|
||||||
if (other.shared != null)
|
|
||||||
return false;
|
|
||||||
} else if (!shared.equals(other.shared))
|
|
||||||
return false;
|
|
||||||
if (tags == null) {
|
|
||||||
if (other.tags != null)
|
|
||||||
return false;
|
|
||||||
} else if (!tags.equals(other.tags))
|
|
||||||
return false;
|
|
||||||
if (type == null) {
|
|
||||||
if (other.type != null)
|
|
||||||
return false;
|
|
||||||
} else if (!type.equals(other.type))
|
|
||||||
return false;
|
|
||||||
if (url == null) {
|
|
||||||
if (other.url != null)
|
|
||||||
return false;
|
|
||||||
} else if (!url.equals(other.url))
|
|
||||||
return false;
|
|
||||||
if (version == null) {
|
|
||||||
if (other.version != null)
|
|
||||||
return false;
|
|
||||||
} else if (!version.equals(other.version))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.jclouds.http.internal.PayloadEnclosingImpl;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.MutableFileInfo;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
|
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default Implementation of {@link PCSFile}.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PCSFileImpl extends PayloadEnclosingImpl implements PCSFile, Comparable<PCSFile> {
|
|
||||||
|
|
||||||
private final MutableFileInfo metadata;
|
|
||||||
private Multimap<String, String> allHeaders = LinkedHashMultimap.create();
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public PCSFileImpl(MutableFileInfo metadata) {
|
|
||||||
super();// no MD5 support
|
|
||||||
this.metadata = metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public MutableFileInfo getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public Multimap<String, String> getAllHeaders() {
|
|
||||||
return allHeaders;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public void setAllHeaders(Multimap<String, String> allHeaders) {
|
|
||||||
this.allHeaders = checkNotNull(allHeaders, "allHeaders");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public int compareTo(PCSFile o) {
|
|
||||||
if (getMetadata().getName() == null)
|
|
||||||
return -1;
|
|
||||||
return (this == o) ? 0 : getMetadata().getName().compareTo(o.getMetadata().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,224 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.domain.internal;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.StorageType;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ResourceInfo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ResourceInfoImpl implements ResourceInfo {
|
|
||||||
|
|
||||||
private final StorageType type;
|
|
||||||
private final URI url;
|
|
||||||
private final String name;
|
|
||||||
private final Date created;
|
|
||||||
private final boolean inProject;
|
|
||||||
private final Date modified;
|
|
||||||
private final String owner;
|
|
||||||
private final int version;
|
|
||||||
private final boolean shared;
|
|
||||||
private final Date accessed;
|
|
||||||
private final long bytes;
|
|
||||||
private final URI tags;
|
|
||||||
private final URI metadata;
|
|
||||||
private final URI parent;
|
|
||||||
|
|
||||||
protected ResourceInfoImpl(StorageType type, URI url, String name, Date created,
|
|
||||||
boolean inProject, Date modified, String owner, int version, boolean shared,
|
|
||||||
Date accessed, long bytes, URI tags, URI metadata, URI parent) {
|
|
||||||
super();
|
|
||||||
this.type = type;
|
|
||||||
this.url = url;
|
|
||||||
this.name = name;
|
|
||||||
this.created = created;
|
|
||||||
this.inProject = inProject;
|
|
||||||
this.modified = modified;
|
|
||||||
this.owner = owner;
|
|
||||||
this.version = version;
|
|
||||||
this.shared = shared;
|
|
||||||
this.accessed = accessed;
|
|
||||||
this.bytes = bytes;
|
|
||||||
this.tags = tags;
|
|
||||||
this.metadata = metadata;
|
|
||||||
this.parent = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(ResourceInfo o) {
|
|
||||||
if (getName() == null)
|
|
||||||
return -1;
|
|
||||||
if (o.getName() == null)
|
|
||||||
return 1;
|
|
||||||
return (this == o) ? 0 : getName().compareTo(o.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreated() {
|
|
||||||
return created;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isInProject() {
|
|
||||||
return inProject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getModified() {
|
|
||||||
return modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getVersion() {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean isShared() {
|
|
||||||
return shared;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getAccessed() {
|
|
||||||
return accessed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getBytes() {
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getMetadata() {
|
|
||||||
return metadata;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((accessed == null) ? 0 : accessed.hashCode());
|
|
||||||
result = prime * result + (int) (bytes ^ (bytes >>> 32));
|
|
||||||
result = prime * result + ((created == null) ? 0 : created.hashCode());
|
|
||||||
result = prime * result + (inProject ? 1231 : 1237);
|
|
||||||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
|
||||||
result = prime * result + ((modified == null) ? 0 : modified.hashCode());
|
|
||||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
|
||||||
result = prime * result + ((owner == null) ? 0 : owner.hashCode());
|
|
||||||
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
|
|
||||||
result = prime * result + (shared ? 1231 : 1237);
|
|
||||||
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
|
||||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
|
||||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
|
||||||
result = prime * result + version;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
ResourceInfoImpl other = (ResourceInfoImpl) obj;
|
|
||||||
if (accessed == null) {
|
|
||||||
if (other.accessed != null)
|
|
||||||
return false;
|
|
||||||
} else if (!accessed.equals(other.accessed))
|
|
||||||
return false;
|
|
||||||
if (bytes != other.bytes)
|
|
||||||
return false;
|
|
||||||
if (created == null) {
|
|
||||||
if (other.created != null)
|
|
||||||
return false;
|
|
||||||
} else if (!created.equals(other.created))
|
|
||||||
return false;
|
|
||||||
if (inProject != other.inProject)
|
|
||||||
return false;
|
|
||||||
if (metadata == null) {
|
|
||||||
if (other.metadata != null)
|
|
||||||
return false;
|
|
||||||
} else if (!metadata.equals(other.metadata))
|
|
||||||
return false;
|
|
||||||
if (modified == null) {
|
|
||||||
if (other.modified != null)
|
|
||||||
return false;
|
|
||||||
} else if (!modified.equals(other.modified))
|
|
||||||
return false;
|
|
||||||
if (name == null) {
|
|
||||||
if (other.name != null)
|
|
||||||
return false;
|
|
||||||
} else if (!name.equals(other.name))
|
|
||||||
return false;
|
|
||||||
if (owner == null) {
|
|
||||||
if (other.owner != null)
|
|
||||||
return false;
|
|
||||||
} else if (!owner.equals(other.owner))
|
|
||||||
return false;
|
|
||||||
if (parent == null) {
|
|
||||||
if (other.parent != null)
|
|
||||||
return false;
|
|
||||||
} else if (!parent.equals(other.parent))
|
|
||||||
return false;
|
|
||||||
if (shared != other.shared)
|
|
||||||
return false;
|
|
||||||
if (tags == null) {
|
|
||||||
if (other.tags != null)
|
|
||||||
return false;
|
|
||||||
} else if (!tags.equals(other.tags))
|
|
||||||
return false;
|
|
||||||
if (type == null) {
|
|
||||||
if (other.type != null)
|
|
||||||
return false;
|
|
||||||
} else if (!type.equals(other.type))
|
|
||||||
return false;
|
|
||||||
if (url == null) {
|
|
||||||
if (other.url != null)
|
|
||||||
return false;
|
|
||||||
} else if (!url.equals(other.url))
|
|
||||||
return false;
|
|
||||||
if (version != other.version)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type Contacts, which represents the user's contact list.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Contacts {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type MetaContainers, which lists the metacontainers available to the
|
|
||||||
* user.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Metacontainers {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type Projects, which lists the projects available to the user.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Projects {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type RecycleBin, which contains the user's deleted files.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Recyclebin {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type Container, which is the user's root Container
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface RootContainer {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type Shares, which lists the items shared to and by the user.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Shares {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type Tags, which lists all the tags applied to the user's files.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface Tags {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.endpoints;
|
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
import javax.inject.Qualifier;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Related to a resource of type WebDAV
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Retention(value = RetentionPolicy.RUNTIME)
|
|
||||||
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
|
||||||
@Qualifier
|
|
||||||
public @interface WebDAV {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,74 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.functions;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
|
||||||
import org.jclouds.rest.InvocationContext;
|
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class AddMetadataItemIntoMap implements Function<HttpResponse, Void>, InvocationContext<AddMetadataItemIntoMap> {
|
|
||||||
ReturnStringIf2xx returnIf200;
|
|
||||||
private GeneratedHttpRequest<?> request;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AddMetadataItemIntoMap(ReturnStringIf2xx returnIf200) {
|
|
||||||
this.returnIf200 = returnIf200;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public Void apply(HttpResponse from) {
|
|
||||||
checkState(request.getArgs() != null, "args should be initialized at this point");
|
|
||||||
Map<String, String> map = null;
|
|
||||||
String key = null;
|
|
||||||
for (Object arg : request.getArgs()) {
|
|
||||||
if (arg instanceof Map)
|
|
||||||
map = (Map<String, String>) arg;
|
|
||||||
else if (arg instanceof String)
|
|
||||||
key = arg.toString();
|
|
||||||
}
|
|
||||||
checkState(map != null, "No Map found in args, improper method declarations");
|
|
||||||
checkState(key != null, "No String found in args, improper method declarations");
|
|
||||||
|
|
||||||
map.put(key, returnIf200.apply(from).trim());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AddMetadataItemIntoMap setContext(HttpRequest request) {
|
|
||||||
checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
|
|
||||||
this.request = (GeneratedHttpRequest<?>) request;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.functions;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ReturnFalseIfContainerNotFound implements Function<Exception, Boolean> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean apply(Exception from) {
|
|
||||||
if (from instanceof ContainerNotFoundException) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
throw Throwables.propagate(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.functions;
|
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpResponseException;
|
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
|
||||||
public class ReturnTrueIfContainerAlreadyExists implements Function<Exception, Boolean> {
|
|
||||||
@Override
|
|
||||||
public Boolean apply(Exception from) {
|
|
||||||
if (from instanceof HttpResponseException) {
|
|
||||||
HttpResponseException responseException = (HttpResponseException) from;
|
|
||||||
if ("The directory already exists.".equals(responseException.getContent())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw Throwables.propagate(from);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.handlers;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpCommand;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.http.HttpRetryHandler;
|
|
||||||
import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles Retryable responses with error codes in the 4xx range
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PCSClientErrorRetryHandler implements HttpRetryHandler {
|
|
||||||
|
|
||||||
private final BackoffLimitedRetryHandler backoffHandler;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public PCSClientErrorRetryHandler(BackoffLimitedRetryHandler backoffHandler) {
|
|
||||||
this.backoffHandler = backoffHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
|
|
||||||
if (response.getStatusCode() == 400) {
|
|
||||||
return backoffHandler.shouldRetryRequest(command, response);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.options;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains options supported in the REST API for the PUT file operation. <h2>
|
|
||||||
* Usage</h2> The recommended way to instantiate a PutFileOptions object is to statically import
|
|
||||||
* PutFileOptions.Builder.* and invoke a static creation method followed by an instance mutator (if
|
|
||||||
* needed):
|
|
||||||
* <p/>
|
|
||||||
* <code>
|
|
||||||
* import static org.jclouds.mezeo.pcs2.options.PutFileOptions.Builder.*
|
|
||||||
* import org.jclouds.mezeo.pcs2.PCSClient;
|
|
||||||
* <p/>
|
|
||||||
* PCSClient connection = // get connection
|
|
||||||
* Future<Void> added = connection.appendFile("container",range(0,3));
|
|
||||||
* <code>
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class PutBlockOptions extends BaseHttpRequestOptions {
|
|
||||||
public static final PutBlockOptions NONE = new PutBlockOptions();
|
|
||||||
private String range;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Multimap<String, String> buildRequestHeaders() {
|
|
||||||
Multimap<String, String> headers = super.buildRequestHeaders();
|
|
||||||
String range = getRange();
|
|
||||||
if (range != null)
|
|
||||||
headers.put("Content-Range", this.getRange());
|
|
||||||
return headers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For use in the header Content-Range
|
|
||||||
* <p />
|
|
||||||
*
|
|
||||||
* @see PutBlockOptions#range(long, long)
|
|
||||||
*/
|
|
||||||
public String getRange() {
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* download the specified range of the object.
|
|
||||||
*/
|
|
||||||
public PutBlockOptions range(long start, long end) {
|
|
||||||
checkArgument(start >= 0, "start must be >= 0");
|
|
||||||
checkArgument(end >= 0, "end must be >= 0");
|
|
||||||
range = String.format("bytes %d-%d/*", start, end);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
/**
|
|
||||||
* @see PutBlockOptions#range(long, long)
|
|
||||||
*/
|
|
||||||
public static PutBlockOptions range(long start, long end) {
|
|
||||||
PutBlockOptions options = new PutBlockOptions();
|
|
||||||
return options.range(start, end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.xml;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSCloudAsyncClient;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses the discovery response from xlink refs.
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class CloudXlinkHandler extends ParseSax.HandlerWithResult<PCSCloudAsyncClient.Response> {
|
|
||||||
|
|
||||||
private Map<String, URI> map = Maps.newHashMap();
|
|
||||||
|
|
||||||
public static class PCSCloudResponseImpl implements PCSCloudAsyncClient.Response {
|
|
||||||
private final Map<String, URI> map;
|
|
||||||
|
|
||||||
public PCSCloudResponseImpl(Map<String, URI> map) {
|
|
||||||
this.map = map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getContactsUrl() {
|
|
||||||
return map.get("contacts");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getMetacontainersUrl() {
|
|
||||||
return map.get("metacontainers");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getProjectsUrl() {
|
|
||||||
return map.get("projects");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getRecyclebinUrl() {
|
|
||||||
return map.get("recyclebin");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getRootContainerUrl() {
|
|
||||||
return map.get("rootContainer");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getSharesUrl() {
|
|
||||||
return map.get("shares");
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI getTagsUrl() {
|
|
||||||
return map.get("tags");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((map == null) ? 0 : map.hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
PCSCloudResponseImpl other = (PCSCloudResponseImpl) obj;
|
|
||||||
if (map == null) {
|
|
||||||
if (other.map != null)
|
|
||||||
return false;
|
|
||||||
} else if (!map.equals(other.map))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "PCSDiscoveryResponseImpl [map=" + map + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public PCSCloudAsyncClient.Response getResult() {
|
|
||||||
return new PCSCloudResponseImpl(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
|
||||||
throws SAXException {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
map.put(qName, URI.create(attributes.getValue(index)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,277 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.xml;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedSet;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.jclouds.date.DateService;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
|
||||||
import org.jclouds.logging.Logger;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ContainerList;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.ResourceInfo;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.ContainerInfoImpl;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.ContainerListImpl;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.FileInfoImpl;
|
|
||||||
import org.jclouds.util.Strings2;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class ContainerHandler extends ParseSax.HandlerWithResult<ContainerList> {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
protected Logger logger = Logger.NULL;
|
|
||||||
|
|
||||||
private SortedSet<ResourceInfo> containerMetadata = Sets.newTreeSet();
|
|
||||||
protected Map<String, URI> metadataItems = Maps.newHashMap();
|
|
||||||
|
|
||||||
private URI rootUrl;
|
|
||||||
private String rootName;
|
|
||||||
private Date rootCreated;
|
|
||||||
private boolean rootInproject;
|
|
||||||
private Date rootModified;
|
|
||||||
private String rootOwner;
|
|
||||||
private int rootVersion;
|
|
||||||
private boolean rootShared;
|
|
||||||
private Date rootAccessed;
|
|
||||||
private long rootBytes;
|
|
||||||
private URI rootParent;
|
|
||||||
private URI rootTags;
|
|
||||||
private URI rootMetadata;
|
|
||||||
|
|
||||||
private URI currentUrl;
|
|
||||||
private String currentName;
|
|
||||||
private Date currentCreated;
|
|
||||||
private boolean currentInproject;
|
|
||||||
private Date currentModified;
|
|
||||||
private String currentOwner;
|
|
||||||
private int currentVersion;
|
|
||||||
private boolean currentShared;
|
|
||||||
private Date currentAccessed;
|
|
||||||
private long currentBytes;
|
|
||||||
private URI currentParent;
|
|
||||||
private URI currentTags;
|
|
||||||
private URI currentMetadata;
|
|
||||||
private URI currentContents;
|
|
||||||
|
|
||||||
private boolean currentPublic;
|
|
||||||
private String currentMimeType;
|
|
||||||
private URI currentContent;
|
|
||||||
private URI currentPermissions;
|
|
||||||
|
|
||||||
private URI currentThumbnail;
|
|
||||||
|
|
||||||
private StringBuilder currentText = new StringBuilder();
|
|
||||||
|
|
||||||
private final DateService dateParser;
|
|
||||||
|
|
||||||
boolean inContainer = false;
|
|
||||||
boolean inContents = false;
|
|
||||||
|
|
||||||
private ContainerListImpl rootContainer;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public ContainerHandler(DateService dateParser) {
|
|
||||||
this.dateParser = dateParser;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContainerList getResult() {
|
|
||||||
return rootContainer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
|
||||||
throws SAXException {
|
|
||||||
if (qName.equals("contents") && attributes.getIndex("count") != -1) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
rootUrl = URI.create(attributes.getValue(index).replace("/contents", ""));
|
|
||||||
}
|
|
||||||
inContents = true;
|
|
||||||
return;
|
|
||||||
} else if (qName.equals("container")) {
|
|
||||||
if (inContents)
|
|
||||||
inContainer = true;
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentUrl = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("parent")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentParent = URI.create(attributes.getValue(index));
|
|
||||||
if (!inContents)
|
|
||||||
rootParent = currentParent;
|
|
||||||
}
|
|
||||||
} else if (qName.equals("file")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentUrl = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("content")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentContent = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("contents")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentContents = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("permissions")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentPermissions = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("tags")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentTags = URI.create(attributes.getValue(index));
|
|
||||||
if (!inContents)
|
|
||||||
rootTags = currentTags;
|
|
||||||
}
|
|
||||||
} else if (qName.equals("thumbnail")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentThumbnail = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("metadata")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentMetadata = URI.create(attributes.getValue(index));
|
|
||||||
if (!inContents)
|
|
||||||
rootMetadata = currentMetadata;
|
|
||||||
}
|
|
||||||
} else if (qName.equals("metadata-item")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
String key = Strings2.replaceAll(attributes.getValue(index), METADATA_PATTERN, "");
|
|
||||||
metadataItems.put(key.toLowerCase(), URI.create(attributes.getValue(index)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final Pattern METADATA_PATTERN = Pattern.compile(".*/metadata/");
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endElement(String uri, String name, String qName) {
|
|
||||||
if (qName.equals("contents")) {
|
|
||||||
if (!inContainer)
|
|
||||||
inContents = false;
|
|
||||||
currentText = new StringBuilder();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (qName.equals("container") && !inContents) {
|
|
||||||
rootContainer = new ContainerListImpl(rootUrl, rootName, rootCreated, rootInproject,
|
|
||||||
rootModified, rootOwner, rootVersion, rootShared, rootAccessed, rootBytes,
|
|
||||||
containerMetadata, rootTags, rootMetadata, metadataItems, rootParent);
|
|
||||||
} else if (qName.equals("container") || qName.equals("file")) {
|
|
||||||
if (qName.equals("container")) {
|
|
||||||
inContainer = false;
|
|
||||||
containerMetadata.add(new ContainerInfoImpl(currentUrl, currentName, currentCreated,
|
|
||||||
currentInproject, currentModified, currentOwner, currentVersion,
|
|
||||||
currentShared, currentAccessed, currentBytes, currentContents, currentTags,
|
|
||||||
currentMetadata, currentParent));
|
|
||||||
} else {
|
|
||||||
containerMetadata.add(new FileInfoImpl(currentUrl, currentName, currentCreated,
|
|
||||||
currentInproject, currentModified, currentOwner, currentVersion,
|
|
||||||
currentShared, currentAccessed, currentPublic, currentMimeType, currentBytes,
|
|
||||||
currentContent, currentParent, currentPermissions, currentTags,
|
|
||||||
currentMetadata, currentThumbnail));
|
|
||||||
}
|
|
||||||
currentUrl = null;
|
|
||||||
currentName = null;
|
|
||||||
currentCreated = null;
|
|
||||||
currentInproject = false;
|
|
||||||
currentModified = null;
|
|
||||||
currentOwner = null;
|
|
||||||
currentVersion = 0;
|
|
||||||
currentShared = false;
|
|
||||||
currentAccessed = null;
|
|
||||||
currentBytes = 0;
|
|
||||||
currentPublic = false;
|
|
||||||
currentMimeType = null;
|
|
||||||
currentParent = null;
|
|
||||||
currentContents = null;
|
|
||||||
currentContent = null;
|
|
||||||
currentPermissions = null;
|
|
||||||
currentTags = null;
|
|
||||||
currentMetadata = null;
|
|
||||||
currentThumbnail = null;
|
|
||||||
|
|
||||||
} else if (qName.equals("name")) {
|
|
||||||
currentName = currentText.toString().trim();
|
|
||||||
if (!inContents)
|
|
||||||
rootName = currentName;
|
|
||||||
} else if (qName.equals("created")) {
|
|
||||||
currentCreated = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
if (!inContents)
|
|
||||||
rootCreated = currentCreated;
|
|
||||||
} else if (qName.equals("inproject")) {
|
|
||||||
currentInproject = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
if (!inContents)
|
|
||||||
rootInproject = currentInproject;
|
|
||||||
} else if (qName.equals("modified")) {
|
|
||||||
currentModified = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
if (!inContents)
|
|
||||||
rootModified = currentModified;
|
|
||||||
} else if (qName.equals("owner")) {
|
|
||||||
currentOwner = currentText.toString().trim();
|
|
||||||
if (!inContents)
|
|
||||||
rootOwner = currentOwner;
|
|
||||||
} else if (qName.equals("version")) {
|
|
||||||
currentVersion = Integer.parseInt(currentText.toString().trim());
|
|
||||||
if (!inContents)
|
|
||||||
rootVersion = currentVersion;
|
|
||||||
} else if (qName.equals("shared")) {
|
|
||||||
currentShared = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
if (!inContents)
|
|
||||||
rootShared = currentShared;
|
|
||||||
} else if (qName.equals("accessed")) {
|
|
||||||
currentAccessed = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
if (!inContents)
|
|
||||||
rootAccessed = currentAccessed;
|
|
||||||
} else if (qName.equals("bytes")) {
|
|
||||||
currentBytes = Long.parseLong(currentText.toString().trim());
|
|
||||||
if (!inContents)
|
|
||||||
rootBytes = currentBytes;
|
|
||||||
} else if (qName.equals("public")) {
|
|
||||||
currentPublic = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("mime_type")) {
|
|
||||||
currentMimeType = currentText.toString().trim();
|
|
||||||
}
|
|
||||||
currentText = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void characters(char ch[], int start, int length) {
|
|
||||||
currentText.append(ch, start, length);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,182 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs.xml;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.jclouds.date.DateService;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.FileInfoWithMetadata;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.internal.FileInfoWithMetadataImpl;
|
|
||||||
import org.jclouds.util.Strings2;
|
|
||||||
import org.xml.sax.Attributes;
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
public class FileHandler extends ParseSax.HandlerWithResult<FileInfoWithMetadata> {
|
|
||||||
private static final Pattern CONTENT_PATTERN = Pattern.compile("/content");
|
|
||||||
private static final Pattern METADATA_PATTERN = Pattern.compile(".*/metadata/");
|
|
||||||
|
|
||||||
protected Map<String, URI> metadataItems = Maps.newHashMap();
|
|
||||||
|
|
||||||
protected URI currentUrl;
|
|
||||||
private String currentName;
|
|
||||||
private Date currentCreated;
|
|
||||||
private boolean currentInproject;
|
|
||||||
private Date currentModified;
|
|
||||||
private String currentOwner;
|
|
||||||
private int currentVersion;
|
|
||||||
private boolean currentShared;
|
|
||||||
private Date currentAccessed;
|
|
||||||
private long currentBytes;
|
|
||||||
private String currentMimeType;
|
|
||||||
private boolean currentPublic;
|
|
||||||
|
|
||||||
protected StringBuilder currentText = new StringBuilder();
|
|
||||||
|
|
||||||
private final DateService dateParser;
|
|
||||||
|
|
||||||
private FileInfoWithMetadata fileMetadataList;
|
|
||||||
|
|
||||||
private URI currentPermissions;
|
|
||||||
|
|
||||||
private URI currentTags;
|
|
||||||
|
|
||||||
private URI currentThumbnail;
|
|
||||||
|
|
||||||
private URI currentMetadata;
|
|
||||||
|
|
||||||
private URI currentContent;
|
|
||||||
|
|
||||||
private URI currentParent;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public FileHandler(DateService dateParser) {
|
|
||||||
this.dateParser = dateParser;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
|
||||||
throws SAXException {
|
|
||||||
if (qName.equals("content")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentContent = URI.create(attributes.getValue(index));
|
|
||||||
currentUrl = URI.create(Strings2.replaceAll(attributes.getValue(index), CONTENT_PATTERN,
|
|
||||||
""));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("permissions")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentPermissions = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("tags")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentTags = URI.create(attributes.getValue(index));
|
|
||||||
|
|
||||||
}
|
|
||||||
} else if (qName.equals("parent")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentParent = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("thumbnail")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentThumbnail = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("metadata")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
currentMetadata = URI.create(attributes.getValue(index));
|
|
||||||
}
|
|
||||||
} else if (qName.equals("metadata-item")) {
|
|
||||||
int index = attributes.getIndex("xlink:href");
|
|
||||||
if (index != -1) {
|
|
||||||
String key = Strings2.replaceAll(attributes.getValue(index), METADATA_PATTERN, "");
|
|
||||||
metadataItems.put(key.toLowerCase(), URI.create(attributes.getValue(index)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void endElement(String uri, String name, String qName) {
|
|
||||||
if (qName.equals("name")) {
|
|
||||||
currentName = currentText.toString().trim();
|
|
||||||
} else if (qName.equals("created")) {
|
|
||||||
currentCreated = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
} else if (qName.equals("inproject")) {
|
|
||||||
currentInproject = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("modified")) {
|
|
||||||
currentModified = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
} else if (qName.equals("owner")) {
|
|
||||||
currentOwner = currentText.toString().trim();
|
|
||||||
} else if (qName.equals("version")) {
|
|
||||||
currentVersion = Integer.parseInt(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("shared")) {
|
|
||||||
currentShared = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("accessed")) {
|
|
||||||
currentAccessed = dateParser.fromSeconds(Long.parseLong(currentText.toString().trim()));
|
|
||||||
} else if (qName.equals("bytes")) {
|
|
||||||
currentBytes = Long.parseLong(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("mime_type")) {
|
|
||||||
currentMimeType = currentText.toString().trim();
|
|
||||||
} else if (qName.equals("public")) {
|
|
||||||
currentPublic = Boolean.parseBoolean(currentText.toString().trim());
|
|
||||||
} else if (qName.equals("file")) {
|
|
||||||
fileMetadataList = new FileInfoWithMetadataImpl(currentUrl, currentName, currentCreated,
|
|
||||||
currentInproject, currentModified, currentOwner, currentVersion, currentShared,
|
|
||||||
currentAccessed, currentPublic, currentMimeType, currentBytes, currentContent,
|
|
||||||
currentParent, currentPermissions, currentTags, currentMetadata, metadataItems,
|
|
||||||
currentThumbnail);
|
|
||||||
currentUrl = null;
|
|
||||||
currentName = null;
|
|
||||||
currentCreated = null;
|
|
||||||
currentInproject = false;
|
|
||||||
currentModified = null;
|
|
||||||
currentOwner = null;
|
|
||||||
currentVersion = 0;
|
|
||||||
currentShared = false;
|
|
||||||
currentAccessed = null;
|
|
||||||
currentBytes = 0;
|
|
||||||
currentMimeType = null;
|
|
||||||
currentPublic = false;
|
|
||||||
}
|
|
||||||
currentText = new StringBuilder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void characters(char ch[], int start, int length) {
|
|
||||||
currentText.append(ch, start, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileInfoWithMetadata getResult() {
|
|
||||||
return fileMetadataList;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,298 +0,0 @@
|
||||||
/**
|
|
||||||
* 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.mezeo.pcs;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest;
|
|
||||||
import org.jclouds.blobstore.functions.ReturnNullOnKeyNotFound;
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.RequiresHttp;
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
|
||||||
import org.jclouds.http.functions.ParseSax;
|
|
||||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
|
||||||
import org.jclouds.http.functions.ReturnInputStream;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSAsyncClient;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSClient;
|
|
||||||
import org.jclouds.mezeo.pcs.PCSCloudAsyncClient.Response;
|
|
||||||
import org.jclouds.mezeo.pcs.blobstore.functions.BlobToPCSFile;
|
|
||||||
import org.jclouds.mezeo.pcs.config.PCSRestClientModule;
|
|
||||||
import org.jclouds.mezeo.pcs.domain.PCSFile;
|
|
||||||
import org.jclouds.mezeo.pcs.functions.AddMetadataItemIntoMap;
|
|
||||||
import org.jclouds.mezeo.pcs.options.PutBlockOptions;
|
|
||||||
import org.jclouds.mezeo.pcs.xml.ContainerHandler;
|
|
||||||
import org.jclouds.mezeo.pcs.xml.FileHandler;
|
|
||||||
import org.jclouds.rest.AsyncClientFactory;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
|
||||||
import org.jclouds.rest.RestContextFactory;
|
|
||||||
import org.jclouds.rest.RestContextSpec;
|
|
||||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|
||||||
import org.testng.annotations.BeforeClass;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import com.google.inject.Module;
|
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests behavior of {@code PCSClient}
|
|
||||||
*
|
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Test(groups = "unit", testName = "pcs2.PCSClientTest")
|
|
||||||
public class PCSAsyncClientTest extends RestClientTest<PCSAsyncClient> {
|
|
||||||
|
|
||||||
public void testList() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("list");
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method);
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://root HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "X-Cloud-Depth: 2\n");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, ContainerHandler.class);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCreateContainer() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("createContainer", String.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, "container");
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://root/contents HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, "<container><name>container</name></container>",
|
|
||||||
"application/vnd.csp.container-info+xml", false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteContainer() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("deleteContainer", URI.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/container/1234"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://localhost/container/1234 HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListURI() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("list", URI.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/mycontainer"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://localhost/mycontainer HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "X-Cloud-Depth: 2\n");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, ContainerHandler.class);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetFileInfo() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("getFileInfo", URI.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/myfile"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://localhost/myfile HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "X-Cloud-Depth: 2\n");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, FileHandler.class);
|
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUploadFile() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("uploadFile", URI.class, PCSFile.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/mycontainer"), blobToPCSFile
|
|
||||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST http://localhost/mycontainer/contents HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, BindBlobToMultipartFormTest.EXPECTS, "multipart/form-data; boundary=--JCLOUDS--",
|
|
||||||
false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ParseURIFromListOrLocationHeaderIf20x.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUploadBlock() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("uploadBlock", URI.class, PCSFile.class, Array.newInstance(
|
|
||||||
PutBlockOptions.class, 0).getClass());
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/mycontainer"), blobToPCSFile
|
|
||||||
.apply(BindBlobToMultipartFormTest.TEST_BLOB));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://localhost/mycontainer/content HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, "hello", "text/plain", false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDownloadFile() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("downloadFile", URI.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/container"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://localhost/container/content HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReturnInputStream.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, ReturnNullOnKeyNotFound.class);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteFile() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("deleteFile", URI.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method,
|
|
||||||
new Object[] { URI.create("http://localhost/contents/file") });
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "DELETE http://localhost/contents/file HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPutMetadata() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("putMetadataItem", URI.class, String.class, String.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/contents/file"), "pow", "bar");
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "PUT http://localhost/contents/file/metadata/pow HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, "bar", "application/unknown", false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAddEntryToMap() throws SecurityException, NoSuchMethodException, IOException {
|
|
||||||
Method method = PCSAsyncClient.class.getMethod("addMetadataItemToMap", URI.class, String.class, Map.class);
|
|
||||||
GeneratedHttpRequest request = processor.createRequest(method, URI.create("http://localhost/pow"), "newkey", ImmutableMap
|
|
||||||
.of("key", "value"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(request, "GET http://localhost/pow/metadata/newkey HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(request, "");
|
|
||||||
assertPayloadEquals(request, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, request, AddMetadataItemIntoMap.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, null);
|
|
||||||
|
|
||||||
checkFilters(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
private BlobToPCSFile blobToPCSFile;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkFilters(HttpRequest request) {
|
|
||||||
assertEquals(request.getFilters().size(), 1);
|
|
||||||
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected TypeLiteral<RestAnnotationProcessor<PCSAsyncClient>> createTypeLiteral() {
|
|
||||||
return new TypeLiteral<RestAnnotationProcessor<PCSAsyncClient>>() {
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
@Override
|
|
||||||
protected void setupFactory() throws IOException {
|
|
||||||
super.setupFactory();
|
|
||||||
blobToPCSFile = injector.getInstance(BlobToPCSFile.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Module createModule() {
|
|
||||||
return new TestPCSRestClientModule();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresHttp
|
|
||||||
@ConfiguresRestClient
|
|
||||||
private static final class TestPCSRestClientModule extends PCSRestClientModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
super.configure();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Response provideCloudResponse(AsyncClientFactory factory) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected URI provideRootContainerUrl(Response response) {
|
|
||||||
return URI.create("http://root");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RestContextSpec<PCSClient, PCSAsyncClient> createContextSpec() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.setProperty("pcs.endpoint", "http://goo");
|
|
||||||
return new RestContextFactory().createContextSpec("pcs", "identity", "credential", properties);
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue