From 5f803f6bd60ce1e01a0aeff9dbd11688929c31af Mon Sep 17 00:00:00 2001 From: Serj Sintsov Date: Fri, 29 Nov 2013 18:30:12 +0300 Subject: [PATCH 1/2] profitbricks: impl: provider base --- profitbricks-c2/pom.xml | 86 ++++ .../java/org/jclouds/profitbricks/PBApi.java | 50 ++ .../profitbricks/PBProviderMetadata.java | 74 +++ .../profitbricks/PBSoapApiMetadata.java | 84 +++ .../compute/PBComputeServiceAdapter.java | 161 ++++++ .../internal/PBTemplateBuilderImpl.java | 52 ++ .../PBComputeServiceAdapterContextModule.java | 66 +++ .../config/PBComputeServiceContextModule.java | 38 ++ .../profitbricks/config/PBHttpApiModule.java | 39 ++ .../jclouds/profitbricks/domain/Server.java | 483 ++++++++++++++++++ .../profitbricks/features/DataCenterApi.java | 37 ++ .../profitbricks/features/FirewallApi.java | 37 ++ .../profitbricks/features/ServerApi.java | 105 ++++ .../filters/PBSoapMessageEnvelope.java | 63 +++ .../functions/ServerToNodeMetadata.java | 119 +++++ .../functions/TemplateToNewServer.java | 49 ++ .../BaseFullServerInfoResponseHandler.java | 56 ++ .../xml/BasePBResponseHandler.java | 91 ++++ .../xml/CreateServerRequestBinder.java | 92 ++++ .../xml/CreateServerResponseHandler.java | 53 ++ .../xml/GetAllServersResponseHandler.java | 57 +++ .../xml/GetServerResponseHandler.java | 51 ++ .../xml/PBApiRequestParameters.java | 33 ++ .../xml/ServerEnumsToStringMapper.java | 23 + .../services/org.jclouds.apis.ApiMetadata | 1 + .../org.jclouds.providers.ProviderMetadata | 1 + .../profitbricks/PBProviderMetadataTest.java | 34 ++ .../profitbricks/PBSoapApiMetadataTest.java | 34 ++ .../compute/PBComputeServiceAdapterTest.java | 34 ++ .../compute/features/BasePBApiTest.java | 69 +++ .../compute/features/ServersApiTest.java | 123 +++++ .../filters/PBSoapMessageEnvelopeTest.java | 52 ++ .../functions/ServerToNodeMetadataTest.java | 131 +++++ .../xml/BasePBResponseHandlerTest.java | 105 ++++ .../xml/CreateServerRequestBinderTest.java | 123 +++++ .../xml/CreateServerResponseHandlerTest.java | 46 ++ .../xml/GetAllServersResponseHandlerTest.java | 132 +++++ .../xml/GetServerResponseHandlerTest.java | 82 +++ .../xml/ServerEnumsToStringMapperTest.java | 51 ++ .../servers/createServerResponse.xml | 12 + .../servers/getAllServersResponse.xml | 51 ++ .../resources/servers/getServerResponse.xml | 22 + 42 files changed, 3102 insertions(+) create mode 100644 profitbricks-c2/pom.xml create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBApi.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBProviderMetadata.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBSoapApiMetadata.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapter.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/domain/internal/PBTemplateBuilderImpl.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceAdapterContextModule.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceContextModule.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBHttpApiModule.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/domain/Server.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/FirewallApi.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/ServerApi.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelope.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/ServerToNodeMetadata.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/TemplateToNewServer.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BaseFullServerInfoResponseHandler.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BasePBResponseHandler.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerRequestBinder.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerResponseHandler.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandler.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetServerResponseHandler.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/PBApiRequestParameters.java create mode 100644 profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java create mode 100644 profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBProviderMetadataTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBSoapApiMetadataTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapterTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/BasePBApiTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/ServersApiTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelopeTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/functions/ServerToNodeMetadataTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/BasePBResponseHandlerTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerRequestBinderTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerResponseHandlerTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandlerTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetServerResponseHandlerTest.java create mode 100644 profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapperTest.java create mode 100644 profitbricks-c2/src/test/resources/servers/createServerResponse.xml create mode 100644 profitbricks-c2/src/test/resources/servers/getAllServersResponse.xml create mode 100644 profitbricks-c2/src/test/resources/servers/getServerResponse.xml diff --git a/profitbricks-c2/pom.xml b/profitbricks-c2/pom.xml new file mode 100644 index 000000000..6539b0615 --- /dev/null +++ b/profitbricks-c2/pom.xml @@ -0,0 +1,86 @@ + + + + 4.0.0 + + + org.apache.jclouds + jclouds-project + 1.7.0-SNAPSHOT + ../../project/pom.xml + + + org.apache.jclouds.provider + profitbricks-c2 + jclouds ProfitBricks Cloud Compute provider + ProfitBricks' implementation of compute provider via SOAP API + bundle + + + + + pbEndpoint + + + + + org.apache.jclouds.api + ec2 + ${project.version} + + + org.apache.jclouds.api + ec2 + ${project.version} + test-jar + test + + + org.apache.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.apache.jclouds + jclouds-compute + ${project.version} + test-jar + test + + + + + org.apache.jclouds.driver + jclouds-log4j + ${project.version} + test + + + org.apache.jclouds.driver + jclouds-sshj + ${project.version} + test + + + + diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBApi.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBApi.java new file mode 100644 index 000000000..371e16cf4 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBApi.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks; + +import com.google.common.base.Optional; +import org.jclouds.profitbricks.features.DataCenterApi; +import org.jclouds.profitbricks.features.FirewallApi; +import org.jclouds.profitbricks.features.ServerApi; +import org.jclouds.rest.annotations.*; + +import java.io.Closeable; + +/** + * Provides access to ProfitBricks's Cloud Compute specific features. + *

+ * As for the current moment ProfitBricks has only SOAP based API and + * REST is coming soon. So, by the default all PB communications are + * delegated to SOAP endpoints. + * + * @author Serj Sintsov + * @see + * @see + * @see + */ +public interface PBApi extends Closeable { + + @Delegate + Optional dataCenterApi(); + + @Delegate + Optional serversApi(); + + @Delegate + Optional firewallApi(); + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBProviderMetadata.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBProviderMetadata.java new file mode 100644 index 000000000..7a2c10dc3 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBProviderMetadata.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import java.net.URI; + +/** + * Implementation of {@link ProviderMetadata} for + * ProfitBricks's Cloud Compute provider. + * + * TODO live test + * + * @author Serj Sintsov + */ +public class PBProviderMetadata extends BaseProviderMetadata { + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public PBProviderMetadata() { + super(builder()); + } + + public PBProviderMetadata(Builder builder) { + super(builder); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder() { + id("profitbricks-c2") + .name("ProfitBricks Cloud Compute 2.0") + .homepage(URI.create("http://www.profitbricks.com")) + .console(URI.create("https://my.profitbricks.com/dashboard/en/index.xhtml")) + .linkedServices("profitbricks-c2") + .apiMetadata(new PBSoapApiMetadata()); + } + + @Override + public PBProviderMetadata build() { + return new PBProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata(ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBSoapApiMetadata.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBSoapApiMetadata.java new file mode 100644 index 000000000..6d0a92b47 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/PBSoapApiMetadata.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.profitbricks.config.PBComputeServiceAdapterContextModule; +import org.jclouds.profitbricks.config.PBComputeServiceContextModule; +import org.jclouds.profitbricks.config.PBHttpApiModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; + +import java.net.URI; +import java.util.Properties; + +/** + * Implementation of {@link org.jclouds.apis.ApiMetadata} for + * ProfitBricks's Cloud Compute based on SOAP API. + * + * @author Serj Sintsov + */ +public class PBSoapApiMetadata extends BaseHttpApiMetadata { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public PBSoapApiMetadata() { + this(new Builder()); + } + + protected PBSoapApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + return BaseHttpApiMetadata.defaultProperties(); + } + + public static class Builder extends BaseHttpApiMetadata.Builder { + + protected Builder() { + id("profitbricks-c2-api") + .name("ProfitBricks Cloud Compute 2.0 SOAP API") + .identityName("Username") + .credentialName("Password") + .documentation(URI.create("http://www.profitbricks.com/apidoc/APIDocumentation.html")) + .defaultEndpoint("https://api.profitbricks.com/1.2") + .version("1.2") + .view(ComputeServiceContext.class) + .defaultProperties(PBSoapApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.>of( + PBComputeServiceContextModule.class, + PBComputeServiceAdapterContextModule.class, + PBHttpApiModule.class + )); + } + + @Override + public PBSoapApiMetadata build() { + return new PBSoapApiMetadata(this); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapter.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapter.java new file mode 100644 index 000000000..328070de1 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapter.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.compute; + +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.domain.*; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.logging.Logger; +import org.jclouds.profitbricks.PBApi; +import org.jclouds.profitbricks.domain.Server; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Designates connection between {@link org.jclouds.compute.ComputeService} API and + * {@link org.jclouds.profitbricks.PBApi} API. + * + * TODO unit and live test + * + * @author Serj Sintsov + */ +@Singleton +public class PBComputeServiceAdapter implements ComputeServiceAdapter { + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + protected PBApi pbApi; + protected Function templateToServer; + + @Inject + public PBComputeServiceAdapter(PBApi pbApi, Function templateToServer) { + this.pbApi = checkNotNull(pbApi, "pbApi"); + this.templateToServer = checkNotNull(templateToServer, "templateToServer"); + } + + @Override + public NodeAndInitialCredentials createNodeWithGroupEncodedIntoName(String group, String name, Template template) { + Server serverToCreate = templateToServer.apply(template); + if (!pbApi.serversApi().isPresent()) return null; // TODO return exception when ComputeServiceAdapter will allow + + logger.trace(">> creating new server from template [%s]", serverToCreate); + String createdServerId = pbApi.serversApi().get().createServer(serverToCreate); + if (createdServerId == null) { + logger.trace("<< server creation failed. template [%s]", serverToCreate); + return null; // TODO return exception when ComputeServiceAdapter will allow + } + logger.trace("<< server created with id=%s", createdServerId); + + logger.trace(">> getting server with id=%s", createdServerId); + Server createdServer = pbApi.serversApi().get().getServer(createdServerId); + logger.trace("<< got server [%s]", createdServer); + + return new NodeAndInitialCredentials( + createdServer, + createdServerId, + LoginCredentials.builder().build() + ); + } + + @Override + public Iterable listImages() { + logger.trace("listing of Images doesn't implemented yet. Return empty iterable collection"); + return ImmutableSet.of(new ImageBuilder() + .id("fake") + .status(Image.Status.AVAILABLE) + .operatingSystem(OperatingSystem.builder() + .family(OsFamily.LINUX) + .description(OsFamily.LINUX.value()) + .build()) + .build()); // todo tmp workaround. provide all possible images + } + + @Override + public Image getImage(String id) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + + @Override + public Iterable listHardwareProfiles() { + logger.trace("listing of Hardware Profiles doesn't implemented yet. Return empty iterable collection"); + return ImmutableSet.of(new HardwareBuilder() + .id("fake") + .processor(new Processor(2, 0)) + .ram(1024) + .build()); // todo tmp workaround. PB doesn't provide predefined hardware profiles + } + + @Override + public Iterable listLocations() { + logger.trace("listing of Locations doesn't implemented yet. Return empty iterable collection"); + return ImmutableSet.of(new LocationBuilder() + .id("ZONE_1") + .description("fake") + .build()); // todo tmp workaround. You can create server without specifying its data center + } + + @Override + public Iterable listNodes() { + if (!pbApi.serversApi().isPresent()) return ImmutableSet.of(); + return pbApi.serversApi().get().getAllServers(); + } + + @Override + public Server getNode(String id) { + checkNotNull(id, "id"); + if (!pbApi.serversApi().isPresent()) return null; + return pbApi.serversApi().get().getServer(id); + } + + @Override + public Iterable listNodesByIds(Iterable ids) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + + @Override + public void destroyNode(String id) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + + @Override + public void rebootNode(String id) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + + @Override + public void resumeNode(String id) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + + @Override + public void suspendNode(String id) { + throw new UnsupportedOperationException("Isn't implemented yet"); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/domain/internal/PBTemplateBuilderImpl.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/domain/internal/PBTemplateBuilderImpl.java new file mode 100644 index 000000000..5226a77fe --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/compute/domain/internal/PBTemplateBuilderImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.compute.domain.internal; + +import com.google.common.base.Supplier; +import org.jclouds.collect.Memoized; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.domain.internal.TemplateBuilderImpl; +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.domain.Location; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Provider; +import java.util.Set; + +/** + * ProfitBricks' {@link TemplateBuilder} implementation. + * + * TODO investigate and leave/remove + * + * @author Serj Sintsov + */ +public class PBTemplateBuilderImpl extends TemplateBuilderImpl { + + @Inject + protected PBTemplateBuilderImpl(@Memoized Supplier> locations, + @Memoized Supplier> images, + @Memoized Supplier> hardwares, + Supplier defaultLocation, + @Named("DEFAULT") Provider optionsProvider, + @Named("DEFAULT") Provider defaultTemplateProvider) { + super(locations, images, hardwares, defaultLocation, optionsProvider, defaultTemplateProvider); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceAdapterContextModule.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceAdapterContextModule.java new file mode 100644 index 000000000..bf90ea6bb --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceAdapterContextModule.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.config; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; +import org.jclouds.compute.ComputeServiceAdapter; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Template; +import org.jclouds.domain.Location; +import org.jclouds.functions.IdentityFunction; +import org.jclouds.profitbricks.compute.PBComputeServiceAdapter; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.functions.ServerToNodeMetadata; +import org.jclouds.profitbricks.functions.TemplateToNewServer; + +/** + * Configuration module with bindings to setup ProfitBricks {@link ComputeServiceAdapter}. + * + * @author Serj Sintsov + */ +public class PBComputeServiceAdapterContextModule + extends ComputeServiceAdapterContextModule { + + @SuppressWarnings("unchecked") + @Override + protected void configure() { + super.configure(); + + bind(new TypeLiteral>() { + }).to(PBComputeServiceAdapter.class); + + bind(new TypeLiteral>() { + }).to(Class.class.cast(ServerToNodeMetadata.class)); + + bind(new TypeLiteral>() { + }).to(Class.class.cast(TemplateToNewServer.class)); + + bind(new TypeLiteral>() { + }).to(Class.class.cast(IdentityFunction.class)); + + bind(new TypeLiteral>() { + }).to(Class.class.cast(IdentityFunction.class)); + + bind(new TypeLiteral>() { + }).to(Class.class.cast(IdentityFunction.class)); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceContextModule.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceContextModule.java new file mode 100644 index 000000000..da15b4646 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBComputeServiceContextModule.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.config; + +import com.google.inject.Binder; +import com.google.inject.Module; +import org.jclouds.compute.domain.*; +import org.jclouds.profitbricks.compute.domain.internal.PBTemplateBuilderImpl; + +/** + * Configuration module with bindings to setup ProfitBricks {@link org.jclouds.compute.ComputeService}. + * + * TODO investigate and leave/remove + * + * @author Serj Sintsov + */ +public class PBComputeServiceContextModule implements Module { + + @Override + public void configure(Binder binder) { + binder.bind(TemplateBuilder.class).to(PBTemplateBuilderImpl.class); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBHttpApiModule.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBHttpApiModule.java new file mode 100644 index 000000000..0db74a182 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/config/PBHttpApiModule.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.config; + +import org.jclouds.profitbricks.PBApi; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.config.HttpApiModule; + +/** + * Configures the {@link org.jclouds.profitbricks.PBApi} connection. + * + * @author Serj Sintsov + */ +@ConfiguresHttpApi +public class PBHttpApiModule extends HttpApiModule { + + @Override + protected void bindErrorHandlers() {} + + @Override + protected void bindRetryHandlers() { + // TODO configure handling of client and server error + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/domain/Server.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/domain/Server.java new file mode 100644 index 000000000..a56aae8ad --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/domain/Server.java @@ -0,0 +1,483 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.domain; + +import com.google.common.base.Objects; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.javax.annotation.Nullable; + +import java.util.Date; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +/** + * Represents information about Virtual Server, such as configuration, + * provisioning status, power status, etc. + * + * TODO move builders to separate files. Revise fields rules + * + * @author Serj Sintsov + */ +public class Server { + + public static ServerCreationBuilder creationBuilder() { + return new ServerCreationBuilder(); + } + + public static ServerDescribingBuilder describingBuilder() { + return new ServerDescribingBuilder(); + } + + public static abstract class Builder> { + + protected String dataCenterId; + protected String serverName; + protected int cores; + protected int ram; + protected boolean internetAccess; + protected OSType osType; + protected AvailabilityZone availabilityZone; + + protected abstract T self(); + + public Server build() { + checkFields(); + return buildInstance(); + } + + protected abstract Server buildInstance(); + + /** + * If left empty, the server will be created in a new data center. + * + * @see Server#getDataCenterId() + */ + public T dataCenterId(String dataCenterId) { + this.dataCenterId = dataCenterId; + return self(); + } + + /** + * @see Server#getServerName() + */ + public T serverName(String serverName) { + this.serverName = serverName; + return self(); + } + + /** + * @see Server#getCores() + */ + public T cores(int cores) { + this.cores = cores; + checkCores(); + return self(); + } + + private void checkCores() { + checkState(cores > 0, "Number of core must be >=1"); + } + + /** + * The minimum RAM size is 256 MiB. + * + * @see Server#getRam() + */ + public T ram(int ram) { + this.ram = ram; + checkRam(); + return self(); + } + + private void checkRam() { + checkState(ram >= 256, "Minimal RAM size is 256 MiB"); + } + + /** + * Set to TRUE to connect the server to the Internet via the specified + * LAN ID. If the LAN is not specified, it is going to be created in + * the next available LAN ID, starting with LAN ID 1. + * + * @see Server#isInternetAccess() + */ + public T internetAccess(boolean internetAccess) { + this.internetAccess = internetAccess; + return self(); + } + + /** + * Sets the zone in which the server is going to be created. + * Servers from different zones are located in different physical locations. + * If set to {@link AvailabilityZone#AUTO} or left empty, servers will be + * created in a random zone. + * + * @see Server#getAvailabilityZone() + */ + public T availabilityZone(AvailabilityZone zone) { + this.availabilityZone = zone; + return self(); + } + + /** + * If left empty, the server will inherit the OS Type of its selected + * boot image/storage. + * + * @see Server#getOsType() + */ + public T osType(OSType osType) { + this.osType = osType; + return self(); + } + + protected void checkFields() { + checkCores(); + checkRam(); + } + } + + /** + * Use this builder to correctly create an new {@link Server} entity which you want to + * add in your cloud. + */ + public static class ServerCreationBuilder extends Builder { + @Override + protected ServerCreationBuilder self() { + return this; + } + + @Override + protected Server buildInstance() { + return new Server(dataCenterId, serverName, cores, ram, internetAccess, osType, availabilityZone); + } + } + + /** + * Use this builder to create an existing server instance from any source. + */ + public static class ServerDescribingBuilder extends Builder { + + protected String serverId; + protected Date creationTime; + protected Date lastModificationTime; + protected ProvisioningState provisioningState; + protected VirtualMachineState virtualMachineState; + + /** + * @see Server#getServerId() + */ + public ServerDescribingBuilder serverId(String serverId) { + this.serverId = checkNotNull(serverId, "serverId"); + return self(); + } + + /** + * @see Server#getCreationTime() + */ + public ServerDescribingBuilder creationTime(Date creationTime) { + this.creationTime = creationTime; + return self(); + } + + /** + * @see Server#getLastModificationTime() + */ + public ServerDescribingBuilder lastModificationTime(Date lastModificationTime) { + this.lastModificationTime = lastModificationTime; + return self(); + } + + /** + * @see Server#getProvisioningState() + */ + public ServerDescribingBuilder provisioningState(ProvisioningState provisioningState) { + this.provisioningState = checkNotNull(provisioningState); + return self(); + } + + /** + * @see Server#getVirtualMachineState() + */ + public ServerDescribingBuilder virtualMachineState(VirtualMachineState virtualMachineState) { + this.virtualMachineState = checkNotNull(virtualMachineState); + return self(); + } + + @Override + protected ServerDescribingBuilder self() { + return this; + } + + @Override + protected void checkFields() { + super.checkFields(); + checkNotNull(serverId, "serverId"); + availabilityZone = availabilityZone == null ? AvailabilityZone.AUTO : availabilityZone; // TODO find checkReturnDefault..or something + osType = osType == null ? OSType.UNKNOWN : osType; + provisioningState = provisioningState == null ? ProvisioningState.UNRECOGNIZED : provisioningState; + virtualMachineState = virtualMachineState == null ? VirtualMachineState.UNRECOGNIZED : virtualMachineState; + } + + @Override + protected Server buildInstance() { + return new Server(dataCenterId, serverId, serverName, cores, ram, internetAccess, osType, availabilityZone, + creationTime, lastModificationTime, provisioningState, virtualMachineState); + } + } + + protected Server(String dataCenterId, String serverName, int cores, int ram, boolean internetAccess, OSType osType, + AvailabilityZone availabilityZone) { + this(dataCenterId, null, serverName, cores, ram, internetAccess, osType, availabilityZone, null, null, null, null); + } + + protected Server(String dataCenterId, String serverId, String serverName, int cores, int ram, boolean internetAccess, + OSType osType, AvailabilityZone availabilityZone, Date creationTime, Date lastModificationTime, + ProvisioningState provisioningState, VirtualMachineState virtualMachineState) { + this.dataCenterId = dataCenterId; + this.serverId = serverId; + this.serverName = serverName; + this.cores = cores; + this.ram = ram; + this.internetAccess = internetAccess; + this.osType = osType; + this.availabilityZone = availabilityZone; + this.creationTime = creationTime; + this.lastModificationTime = lastModificationTime; + this.provisioningState = provisioningState; + this.virtualMachineState = virtualMachineState; + } + + public enum ProvisioningState { + INACTIVE, INPROCESS, AVAILABLE, DELETED, ERROR, UNRECOGNIZED; + + public String value() { + return name(); + } + + public static ProvisioningState fromValue(String value) { + try { + return valueOf(value); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public enum VirtualMachineState { + NOSTATE, RUNNING, BLOCKED, PAUSED, SHUTDOWN, SHUTOFF, CRASHED, UNRECOGNIZED; + + public String value() { + return name(); + } + + public static VirtualMachineState fromValue(String value) { + try { + return valueOf(value); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + } + + public enum OSType { + WINDOWS, LINUX, OTHER, UNKNOWN; + + public String value() { + return name(); + } + + public static OSType fromValue(String value) { + try { + return valueOf(value); + } catch (IllegalArgumentException e) { + return UNKNOWN; + } + } + } + + public enum AvailabilityZone { + AUTO, ZONE_1, ZONE_2; + + public String value() { + return name(); + } + + public static AvailabilityZone fromValue(String value) { + try { + return valueOf(value); + } catch (IllegalArgumentException e) { + return AUTO; + } + } + + public Location toLocation() { + return toLocation(null); + } + + public Location toLocation(Location parent) { + return new LocationBuilder() + .id(value()) + .description(value()) + .scope(LocationScope.ZONE) + .parent(parent) + .build(); + } + } + + private String dataCenterId; + private String serverId; + + @Nullable + private String serverName; + + private int cores; + private int ram; + private boolean internetAccess; + + @Nullable + private Date creationTime; + @Nullable + private Date lastModificationTime; + + private ProvisioningState provisioningState; + private VirtualMachineState virtualMachineState; + + private OSType osType; + private AvailabilityZone availabilityZone; + + /** + * Defines the data center wherein the server is to be created. + */ + public String getDataCenterId() { + return dataCenterId; + } + + /** + * Identifier of the virtual server + */ + public String getServerId() { + return serverId; + } + + /** + * Emptiable. Outputs the name of the specified virtual server + */ + public String getServerName() { + return serverName; + } + + /** + * Number of cores to be assigned to the specified server + */ + public int getCores() { + return cores; + } + + /** + * Number of RAM memory (in MiB) to be assigned to the server. + * The minimum RAM size is 256 MiB + */ + public int getRam() { + return ram; + } + + /** + * Returns {@code true} if server is connected to a public LAN + */ + public boolean isInternetAccess() { + return internetAccess; + } + + /** + * Nullable. Time when the specified virtual server has been created + */ + public Date getCreationTime() { + return creationTime; + } + + /** + * Nullable. Time when the specified virtual server has last been modified + */ + public Date getLastModificationTime() { + return lastModificationTime; + } + + /** + * Describes the current provisioning state of the specified virtual server + */ + public ProvisioningState getProvisioningState() { + return provisioningState; + } + + /** + * Describes the current server state of the specified virtual server + */ + public VirtualMachineState getVirtualMachineState() { + return virtualMachineState; + } + + /** + * OS type of the server + */ + public OSType getOsType() { + return osType; + } + + /** + * Zone in which the server is located + */ + public AvailabilityZone getAvailabilityZone() { + return availabilityZone; + } + + @Override + public int hashCode() { + return Objects.hashCode(serverId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + Server that = Server.class.cast(obj); + + return Objects.equal(this.serverId, that.serverId); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "{" + + "dataCenterId=" + dataCenterId + "," + + "serverId=" + serverId + "," + + "serverName=" + serverName + "," + + "internetAccess=" + internetAccess + "," + + "creationTime=" + creationTime + "," + + "lastModificationTime=" + lastModificationTime + "," + + "cores=" + cores + "," + + "ram=" + ram + "," + + "osType=" + osType + "," + + "provisioningState=" + provisioningState + "," + + "virtualMachineState=" + virtualMachineState + "," + + "availabilityZone=" + availabilityZone + + "}"; + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java new file mode 100644 index 000000000..c2eceb1ee --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/DataCenterApi.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.features; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.profitbricks.filters.PBSoapMessageEnvelope; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SinceApiVersion; +import org.jclouds.rest.annotations.VirtualHost; + +/** + * Provides synchronous access to ProfitBricks's Virtual Data Center Operations API. + * + * @author Serj Sintsov + */ +@SinceApiVersion("1.2") +@RequestFilters({BasicAuthentication.class, PBSoapMessageEnvelope.class}) +@VirtualHost +public interface DataCenterApi { + + // TODO coming soon + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/FirewallApi.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/FirewallApi.java new file mode 100644 index 000000000..7761672a5 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/FirewallApi.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.features; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.profitbricks.filters.PBSoapMessageEnvelope; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SinceApiVersion; +import org.jclouds.rest.annotations.VirtualHost; + +/** + * Provides synchronous access to ProfitBricks's Firewall Operations API. + * + * @author Serj Sintsov + */ +@SinceApiVersion("1.2") +@RequestFilters({BasicAuthentication.class, PBSoapMessageEnvelope.class}) +@VirtualHost +public interface FirewallApi { + + // TODO coming soon + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/ServerApi.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/ServerApi.java new file mode 100644 index 000000000..d14cb075f --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/features/ServerApi.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.features; + +import static org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; +import static org.jclouds.Fallbacks.NullOnNotFoundOr404; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.filters.PBSoapMessageEnvelope; +import org.jclouds.profitbricks.xml.CreateServerRequestBinder; +import org.jclouds.profitbricks.xml.CreateServerResponseHandler; +import org.jclouds.profitbricks.xml.GetAllServersResponseHandler; +import org.jclouds.profitbricks.xml.GetServerResponseHandler; +import static org.jclouds.profitbricks.xml.PBApiRequestParameters.SERVER_ENTITY; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.SinceApiVersion; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.MapBinder; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.Set; + +/** + * Provides synchronous access to ProfitBricks's Server Operations API. + * + * TODO handle request/response errors + * + * @author Serj Sintsov + */ +@SinceApiVersion("1.2") +@RequestFilters({BasicAuthentication.class, PBSoapMessageEnvelope.class}) +@VirtualHost +public interface ServerApi { + + /** + * Returns information about all virtual server, such as + * configuration, provisioning status, power status, etc. + * + * @return servers in your cloud data centers or empty if there are none + */ + @POST // TODO live and expect test + @Named("GetAllServers") + @Consumes(MediaType.TEXT_XML) + @Produces(MediaType.TEXT_XML) + @Payload("") + @XMLResponseParser(GetAllServersResponseHandler.class) + @Fallback(EmptySetOnNotFoundOr404.class) + Set getAllServers(); + + + /** + * Returns information about a virtual server, + * such as configuration, provisioning status, power status, etc. + * + * @param serverId server identificator + * @return an existing {@link Server} or {@code null} + */ + @POST // TODO live and expect test + @Named("GetServer") + @Consumes(MediaType.TEXT_XML) + @Produces(MediaType.TEXT_XML) + @Payload("{id}") + @XMLResponseParser(GetServerResponseHandler.class) + @Fallback(NullOnNotFoundOr404.class) + Server getServer(@PayloadParam("id") String serverId); + + /** + * Creates a Virtual Server. + * + * @param server server entity to create + * @return server identifier or {@code null} if creation is failed + */ + @POST // TODO live and expect test + @Named("CreateServer") + @Consumes(MediaType.TEXT_XML) + @Produces(MediaType.TEXT_XML) + @MapBinder(CreateServerRequestBinder.class) + @XMLResponseParser(CreateServerResponseHandler.class) + @Fallback(NullOnNotFoundOr404.class) + String createServer(@PayloadParam(SERVER_ENTITY) Server server); + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelope.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelope.java new file mode 100644 index 000000000..2936b81d8 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelope.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.filters; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.logging.Logger; + +import javax.annotation.Resource; +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; +import javax.xml.soap.MimeHeader; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Filters {@link HttpRequest} request and wraps request body into SOAP envelope. + * + * @author Serj Sintsov + */ +@Singleton +public class PBSoapMessageEnvelope implements HttpRequestFilter { + + @Resource + private Logger logger = Logger.NULL; + + private static final String SOAP_MSG_PREFIX = + "" + + "" + + ""; + + private static final String SOAP_MSG_SUFFIX = ""; + + public HttpRequest filter(HttpRequest request) { + checkNotNull(request.getPayload(), "HTTP Request must contain payload message"); + return createSoapRequest(request); + } + + private HttpRequest createSoapRequest(HttpRequest request) { + String body = request.getPayload().getRawContent().toString(); + logger.trace("wrapping request payload [%s] into SOAP envelope", body); + Payload soapPayload = Payloads.newStringPayload(SOAP_MSG_PREFIX + body + SOAP_MSG_SUFFIX); + soapPayload.getContentMetadata().setContentType(MediaType.TEXT_XML); + return request.toBuilder().payload(soapPayload).build(); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/ServerToNodeMetadata.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/ServerToNodeMetadata.java new file mode 100644 index 000000000..e5f2a8710 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/ServerToNodeMetadata.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.functions; + +import com.google.common.base.Function; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.profitbricks.domain.Server; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * A function for transforming a ProfitBricks {@link Server} into a generic + * NodeMetadata object. + * + * @author Serj Sintsov + */ +public class ServerToNodeMetadata implements Function { + + @Override + public NodeMetadata apply(Server server) { + checkNotNull(server, "server"); + + Location region = new LocationBuilder() + .id(server.getDataCenterId()) + .description(server.getDataCenterId()) + .scope(LocationScope.REGION) + .build(); + + /** + * ProfitBricks locate servers in several availability zones + * {@link org.jclouds.profitbricks.domain.Server.AvailabilityZone}. + * For the moment we don't know iso codes for this zones. + */ + Location serverZone = server.getAvailabilityZone().toLocation(region); + + HardwareBuilder hardwareBuilder = new HardwareBuilder() + .id(server.getServerId()) + .processor(new Processor(server.getCores(), 0)) + .ram(server.getRam()) + .location(serverZone); + + NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder() + .id(server.getServerId()) + .providerId(server.getServerId()) + .name(server.getServerName()) + .hostname(server.getServerName()) + .status(mapStatus(server.getVirtualMachineState())) + .operatingSystem(mapOS(server.getOsType())) + .hardware(hardwareBuilder.build()) + .location(region); + + return nodeMetadataBuilder.build(); + } + + // TODO move to configuration module + protected OperatingSystem mapOS(Server.OSType osType) { + if (osType == null) + return OperatingSystem.builder() + .description(OsFamily.UNRECOGNIZED.value()) + .family(OsFamily.UNRECOGNIZED) + .build(); + + switch (osType) { + case WINDOWS: + return OperatingSystem.builder() + .description(OsFamily.WINDOWS.value()) + .family(OsFamily.WINDOWS) + .build(); + case LINUX: + return OperatingSystem.builder() + .description(OsFamily.LINUX.value()) + .family(OsFamily.LINUX) + .build(); + default: + return OperatingSystem.builder() + .description(OsFamily.UNRECOGNIZED.value()) + .family(OsFamily.UNRECOGNIZED) + .build(); + } + } + + // TODO move to configuration module + protected NodeMetadata.Status mapStatus(Server.VirtualMachineState state) { + if (state == null) return NodeMetadata.Status.UNRECOGNIZED; + + switch (state) { + case SHUTDOWN: + case SHUTOFF: + case PAUSED: return NodeMetadata.Status.SUSPENDED; + case RUNNING: return NodeMetadata.Status.RUNNING; + case BLOCKED: return NodeMetadata.Status.PENDING; + case CRASHED: return NodeMetadata.Status.ERROR; + default: return NodeMetadata.Status.UNRECOGNIZED; + } + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/TemplateToNewServer.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/TemplateToNewServer.java new file mode 100644 index 000000000..022045cf1 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/functions/TemplateToNewServer.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.functions; + +import com.google.common.base.Function; +import org.jclouds.compute.domain.Template; +import org.jclouds.profitbricks.domain.Server; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Function for transforming user general node Template to ProfitBricks + * {@link org.jclouds.profitbricks.domain.Server} spec to create new virtual server. + * + * TODO test + * + * @author Serj Sintsov + */ +public class TemplateToNewServer implements Function { + + @Override + public Server apply(Template template) { + checkNotNull(template, "template"); + + return Server.creationBuilder() + // .dataCenterId(template.getLocation().getId()) // todo DC is an Optional param according to the API + .serverName(template.getHardware().getName()) + .cores((int) template.getHardware().getProcessors().get(0).getCores()) + .ram(template.getHardware().getRam()) + .availabilityZone(Server.AvailabilityZone.ZONE_1) + .osType(Server.OSType.fromValue(template.getImage().getOperatingSystem().getFamily().name())) + .build(); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BaseFullServerInfoResponseHandler.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BaseFullServerInfoResponseHandler.java new file mode 100644 index 000000000..03be76698 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BaseFullServerInfoResponseHandler.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Server; + +import javax.inject.Inject; + +import static org.jclouds.profitbricks.domain.Server.*; + +/** + * Parses XML response on GetAllServers request. + * + * @author Serj Sintsov + */ +public abstract class BaseFullServerInfoResponseHandler extends BasePBResponseHandler { + + protected ServerDescribingBuilder describingBuilder; + + @Inject + public BaseFullServerInfoResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + describingBuilder = Server.describingBuilder(); + } + + protected void setServerInfoOnEndElementEvent(String qName) { + if (qName.equals("ram")) describingBuilder.ram(textBufferToIntValue()); + else if (qName.equals("cores")) describingBuilder.cores(textBufferToIntValue()); + else if (qName.equals("osType")) describingBuilder.osType(OSType.fromValue(trimAndGetTagStrValue())); + else if (qName.equals("serverId")) describingBuilder.serverId(trimAndGetTagStrValue()); + else if (qName.equals("serverName")) describingBuilder.serverName(trimAndGetTagStrValue()); + else if (qName.equals("dataCenterId")) describingBuilder.dataCenterId(trimAndGetTagStrValue()); + else if (qName.equals("creationTime")) describingBuilder.creationTime(textBufferToIso8601Date()); + else if (qName.equals("internetAccess")) describingBuilder.internetAccess(textBufferToBoolValue()); + else if (qName.equals("availabilityZone")) describingBuilder.availabilityZone(AvailabilityZone.fromValue(trimAndGetTagStrValue())); + else if (qName.equals("provisioningState")) describingBuilder.provisioningState(ProvisioningState.fromValue(trimAndGetTagStrValue())); + else if (qName.equals("virtualMachineState")) describingBuilder.virtualMachineState(VirtualMachineState.fromValue(trimAndGetTagStrValue())); + else if (qName.equals("lastModificationTime")) describingBuilder.lastModificationTime(textBufferToIso8601Date()); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BasePBResponseHandler.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BasePBResponseHandler.java new file mode 100644 index 000000000..6bbdb6628 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/BasePBResponseHandler.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.annotations.VisibleForTesting; +import org.jclouds.date.DateCodec; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.http.functions.ParseSax; + +import java.util.Date; + +/** + * Base ProfitBricks response handler with some useful methods. + * + * @author Serj Sintsov + */ +public abstract class BasePBResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + protected final DateCodec dateCodec; + + private StringBuilder textBuf; + + public BasePBResponseHandler(DateCodecFactory dateCodecFactory) { + dateCodec = checkNotNull(checkNotNull(dateCodecFactory, "dateCodecFactory").iso8601(), "iso8601 date codec"); + textBuf = new StringBuilder(); + } + + /** + * Uses {@link #trimAndGetTagStrValue()} + */ + @VisibleForTesting + protected final Date textBufferToIso8601Date() { + return dateCodec.toDate(trimAndGetTagStrValue()); + } + + @VisibleForTesting + protected String textBufferValue() { + return textBuf.toString(); + } + + /** + * Uses {@link #textBufferValue()} + */ + @VisibleForTesting + protected String trimAndGetTagStrValue() { + return textBufferValue().trim(); + } + + /** + * Uses {@link #trimAndGetTagStrValue()} + */ + @VisibleForTesting + protected int textBufferToIntValue() { + return Integer.parseInt(trimAndGetTagStrValue()); + } + + /** + * Uses {@link #trimAndGetTagStrValue()} + */ + @VisibleForTesting + protected boolean textBufferToBoolValue() { + return Boolean.parseBoolean(trimAndGetTagStrValue()); + } + + @VisibleForTesting + protected void clearTextBuffer() { + textBuf = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + textBuf.append(ch, start, length); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerRequestBinder.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerRequestBinder.java new file mode 100644 index 000000000..6d999405b --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerRequestBinder.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import com.google.common.base.Strings; +import org.jclouds.http.HttpRequest; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.rest.MapBinder; + +import javax.inject.Inject; +import javax.ws.rs.core.MediaType; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Create XML payload to send new server creation request. + * + * @author Serj Sintsov + */ +public class CreateServerRequestBinder implements MapBinder { + + private ServerEnumsToStringMapper serverEnumsMapper; + + @Inject + public CreateServerRequestBinder(ServerEnumsToStringMapper serverEnumsMapper) { + this.serverEnumsMapper = checkNotNull(serverEnumsMapper, "serverEnumsMapper"); + } + + @Override + public R bindToRequest(R request, Map postParams) { + checkNotNull(request, "request"); + + Object serverObj = postParams.get(PBApiRequestParameters.SERVER_ENTITY); + checkNotNull(serverObj, "server"); + Server server = Server.class.cast(serverObj); + + return createRequest(request, generateRequestPayload(server)); + } + + private String generateRequestPayload(Server server) { + return "" + + "" + + addIfNotEmpty("%s", server.getDataCenterId()) + + addIfNotEmpty("%s", server.getServerName()) + + justAdd("%s", server.getCores()) + + justAdd("%s", server.getRam()) + + justAdd("%s", server.isInternetAccess()) + + addIfNotEmpty("%s", serverEnumsMapper.mapOSType(server.getOsType())) + + addIfNotEmpty("%s", serverEnumsMapper.mapAvailabilityZone(server.getAvailabilityZone())) + + "" + + ""; + } + + private String addIfNotEmpty(String pattern, String param) { + return Strings.isNullOrEmpty(param) ? "" : String.format(pattern, param); + } + + private String justAdd(String pattern, int param) { + return String.format(pattern, param); + } + + private String justAdd(String pattern, boolean param) { + return String.format(pattern, param); + } + + private R createRequest(R fromRequest, String payload) { + fromRequest.setPayload(payload); + fromRequest.getPayload().getContentMetadata().setContentType(MediaType.TEXT_XML); + return fromRequest; + } + + @Override + public R bindToRequest(R request, Object input) { + throw new UnsupportedOperationException("Use bind method with post parameters instead"); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerResponseHandler.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerResponseHandler.java new file mode 100644 index 000000000..4493b54dc --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/CreateServerResponseHandler.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.date.DateCodecFactory; + +import javax.inject.Inject; + +/** + * XML parser to handle CreateServer success response. + * + * @author Serj Sintsov + */ +public class CreateServerResponseHandler extends BasePBResponseHandler { + + private boolean isDone; + private String serverId; + + @Inject + public CreateServerResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + } + + @Override + public String getResult() { + return serverId; + } + + @Override + public void endElement(String uri, String name, String qName) { + if (isDone) return; + if (qName.equals("serverId")) { + serverId = trimAndGetTagStrValue(); + isDone = true; + } + clearTextBuffer(); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandler.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandler.java new file mode 100644 index 000000000..0c6e58af7 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandler.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import com.google.common.collect.Sets; +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Server; + +import javax.inject.Inject; + +import java.util.Set; + +/** + * XML parser to handle success response on GetAllServers request. + * + * @author Serj Sintsov + */ +public class GetAllServersResponseHandler extends BaseFullServerInfoResponseHandler> { + + private Set servers; + + @Inject + public GetAllServersResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + servers = Sets.newHashSet(); + } + + @Override + public Set getResult() { + return servers; + } + + @Override + public void endElement(String uri, String name, String qName) { + setServerInfoOnEndElementEvent(qName); + if (qName.equals("return")) { + servers.add(describingBuilder.build()); + describingBuilder = Server.describingBuilder(); + } + clearTextBuffer(); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetServerResponseHandler.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetServerResponseHandler.java new file mode 100644 index 000000000..16c192d21 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/GetServerResponseHandler.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.date.DateCodecFactory; +import org.jclouds.profitbricks.domain.Server; + +import javax.inject.Inject; + +/** + * XML parser to handle success response on GetServer request. + * + * @author Serj Sintsov + */ +public class GetServerResponseHandler extends BaseFullServerInfoResponseHandler { + + private boolean isDone; + + @Inject + public GetServerResponseHandler(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + } + + @Override + public Server getResult() { + return describingBuilder.build(); + } + + @Override + public void endElement(String uri, String name, String qName) { + if (isDone) return; + setServerInfoOnEndElementEvent(qName); + if (qName.equals("return")) isDone = true; + clearTextBuffer(); + } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/PBApiRequestParameters.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/PBApiRequestParameters.java new file mode 100644 index 000000000..7df9101b2 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/PBApiRequestParameters.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +/** + * Contains ProfitBricks requests parameters values. + * + * @author Serj Sintsov + */ +public final class PBApiRequestParameters { + + /** + * Used to pass {@link org.jclouds.profitbricks.domain.Server} entity into payload + */ + public static final String SERVER_ENTITY = "server"; + + private PBApiRequestParameters() { } + +} diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java new file mode 100644 index 000000000..8c845a0b4 --- /dev/null +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java @@ -0,0 +1,23 @@ +package org.jclouds.profitbricks.xml; + +import org.jclouds.profitbricks.domain.Server; + +import javax.inject.Singleton; + +/** + * Maps {@link Server} specific enums to strings. Useful in the requests binders. + * + * @author Serj Sintsov + */ +@Singleton +public class ServerEnumsToStringMapper { + + public String mapOSType(Server.OSType osType) { + return osType == null ? "" : osType.value(); + } + + public String mapAvailabilityZone(Server.AvailabilityZone zone) { + return zone == null ? "" : zone.value(); + } + +} diff --git a/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 000000000..48f195938 --- /dev/null +++ b/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.profitbricks.PBSoapApiMetadata diff --git a/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 000000000..7d84b723d --- /dev/null +++ b/profitbricks-c2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.profitbricks.PBProviderMetadata diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBProviderMetadataTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBProviderMetadataTest.java new file mode 100644 index 000000000..e88d131e0 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBProviderMetadataTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks; + +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * Test for {@link PBProviderMetadata} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "PBProviderMetadataTest") +public class PBProviderMetadataTest extends BaseProviderMetadataTest { + + public PBProviderMetadataTest() { + super(new PBProviderMetadata(), new PBSoapApiMetadata()); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBSoapApiMetadataTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBSoapApiMetadataTest.java new file mode 100644 index 000000000..354fb8cc6 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/PBSoapApiMetadataTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks; + +import org.jclouds.compute.internal.BaseComputeServiceApiMetadataTest; +import org.testng.annotations.Test; + +/** + * Test for {@code PBApi} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "PBSoapApiMetadata") +public class PBSoapApiMetadataTest extends BaseComputeServiceApiMetadataTest { + + public PBSoapApiMetadataTest() { + super(new PBSoapApiMetadata()); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapterTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapterTest.java new file mode 100644 index 000000000..3043c9ede --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/PBComputeServiceAdapterTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.compute; + +import org.testng.annotations.Test; + +/** + * Test for {@link PBComputeServiceAdapter} + * TODO finish + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "PBComputeServiceAdapterTest") +public class PBComputeServiceAdapterTest { + + @Test + public void listNodes() { + + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/BasePBApiTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/BasePBApiTest.java new file mode 100644 index 000000000..d33e597f6 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/BasePBApiTest.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.compute.features; + +import com.google.inject.Module; +import org.jclouds.apis.ApiMetadata; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.profitbricks.PBSoapApiMetadata; +import org.jclouds.profitbricks.config.PBHttpApiModule; +import org.jclouds.profitbricks.filters.PBSoapMessageEnvelope; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.internal.BaseAsyncApiTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * Base ProfitBricks API test + * + * @author Serj Sintsov + */ +@Test(groups = "unit") +public abstract class BasePBApiTest extends BaseAsyncApiTest { + + protected final String HTTP_HEADERS = "Accept: text/xml\n" + + "Host: api.profitbricks.com\n"; + + @ConfiguresHttpApi + public static class BasePBApiTestModule extends PBHttpApiModule { } + + @Override + protected Module createModule() { + return new BasePBApiTestModule(); + } + + @Override + protected ApiMetadata createApiMetadata() { + return new PBSoapApiMetadata(); + } + + @Override + protected void checkFilters(HttpRequest request) { + assertEquals(request.getFilters().size(), 2); + assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); + assertEquals(request.getFilters().get(1).getClass(), PBSoapMessageEnvelope.class); + } + + protected void checkHeaders(GeneratedHttpRequest request) { + assertNonPayloadHeadersEqual(request, HTTP_HEADERS); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/ServersApiTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/ServersApiTest.java new file mode 100644 index 000000000..4f61e7e38 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/compute/features/ServersApiTest.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.compute.features; + +import com.google.common.collect.ImmutableList; +import org.jclouds.Fallbacks; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.profitbricks.domain.Server; +import org.jclouds.profitbricks.features.ServerApi; +import org.jclouds.profitbricks.xml.CreateServerResponseHandler; +import org.jclouds.profitbricks.xml.GetAllServersResponseHandler; +import org.jclouds.profitbricks.xml.GetServerResponseHandler; +import org.jclouds.reflect.Invocation; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import static org.testng.Assert.assertNotNull; +import org.testng.annotations.Test; + +import java.io.IOException; + +import static org.jclouds.reflect.Reflection2.method; + +/** + * Test for {@link org.jclouds.profitbricks.features.ServerApi} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "ServersApiTest") +public class ServersApiTest extends BasePBApiTest { + + @Test + public void getAllServers() throws SecurityException, NoSuchMethodException, IOException { + Invocation invocation = Invocation.create(method(ServerApi.class, "getAllServers")); + + GeneratedHttpRequest request = processor.apply(invocation); + + checkFilters(request); + + assertRequestLineEquals(request, "POST https://api.profitbricks.com/1.2 HTTP/1.1"); + assertPayloadEquals(request, "", "text/xml", false); + assertResponseParserClassEquals(invocation.getInvokable(), request, ParseSax.class); + assertSaxResponseParserClassEquals(invocation.getInvokable(), GetAllServersResponseHandler.class); + assertFallbackClassEquals(invocation.getInvokable(), Fallbacks.EmptySetOnNotFoundOr404.class); + + checkHeaders(request); + } + + @Test + public void getServer() throws SecurityException, NoSuchMethodException, IOException { + Invocation invocation = Invocation.create( + method(ServerApi.class, "getServer", String.class), + ImmutableList.of("93981076-2511-4aa7-82c0-1e4df0d1737f") + ); + + GeneratedHttpRequest request = processor.apply(invocation); + assertNotNull(request); + + checkFilters(request); + + assertRequestLineEquals(request, "POST https://api.profitbricks.com/1.2 HTTP/1.1"); + assertPayloadEquals(request, "93981076-2511-4aa7-82c0-1e4df0d1737f", "text/xml", false); + assertResponseParserClassEquals(invocation.getInvokable(), request, ParseSax.class); + assertSaxResponseParserClassEquals(invocation.getInvokable(), GetServerResponseHandler.class); + assertFallbackClassEquals(invocation.getInvokable(), Fallbacks.NullOnNotFoundOr404.class); + + checkHeaders(request); + } + + @Test + public void createServer() throws SecurityException, NoSuchMethodException, IOException { + Invocation invocation = Invocation.create( + method(ServerApi.class, "createServer", Server.class), + ImmutableList.of(Server.creationBuilder() + .dataCenterId("79046edb-2a50-4d0f-a153-6576ee7d22a6") + .cores(1) + .ram(256) + .serverName("tomcatServer") + .osType(Server.OSType.OTHER) + .availabilityZone(Server.AvailabilityZone.ZONE_1) + .internetAccess(true) + .build()) + ); + + String expectedPayload = "" + + "" + + "79046edb-2a50-4d0f-a153-6576ee7d22a6" + + "tomcatServer" + + "1" + + "256" + + "true" + + "OTHER" + + "ZONE_1" + + "" + + ""; + + GeneratedHttpRequest request = processor.apply(invocation); + assertNotNull(request); + + checkFilters(request); + + assertRequestLineEquals(request, "POST https://api.profitbricks.com/1.2 HTTP/1.1"); + assertPayloadEquals(request, expectedPayload, "text/xml", false); + assertResponseParserClassEquals(invocation.getInvokable(), request, ParseSax.class); + assertSaxResponseParserClassEquals(invocation.getInvokable(), CreateServerResponseHandler.class); + assertFallbackClassEquals(invocation.getInvokable(), Fallbacks.NullOnNotFoundOr404.class); + + checkHeaders(request); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelopeTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelopeTest.java new file mode 100644 index 000000000..bc3072e7c --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/filters/PBSoapMessageEnvelopeTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.filters; + +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * Test for {@link PBSoapMessageEnvelope} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "PBSoapMessageEnvelopeTest") +public class PBSoapMessageEnvelopeTest { + + private static final String SOAP_MSG_PREFIX = + "" + + "" + + ""; + + private static final String SOAP_MSG_SUFFIX = ""; + + @Test + public void testWithId() { + PBSoapMessageEnvelope filter = new PBSoapMessageEnvelope(); + HttpRequest req = filter.filter( + HttpRequest.builder() + .payload("") + .method("GET") + .endpoint("http://www.endpoint.com") + .build() + ); + assertEquals(req.getPayload().getRawContent().toString(), SOAP_MSG_PREFIX + "" + SOAP_MSG_SUFFIX); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/functions/ServerToNodeMetadataTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/functions/ServerToNodeMetadataTest.java new file mode 100644 index 000000000..1d6132f4f --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/functions/ServerToNodeMetadataTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.functions; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.domain.LocationScope; +import org.jclouds.profitbricks.domain.Server; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.BLOCKED; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.CRASHED; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.RUNNING; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.PAUSED; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.SHUTDOWN; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.SHUTOFF; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.NOSTATE; +import static org.jclouds.profitbricks.domain.Server.VirtualMachineState.UNRECOGNIZED; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Test for {@link ServerToNodeMetadata} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "ServerToNodeMetadataTest") +public class ServerToNodeMetadataTest { + + @Test + public void testApply() { + ServerToNodeMetadata func = new ServerToNodeMetadata(); + Server actualServer = actualServer(); + NodeMetadata nodeMetadata = func.apply(actualServer); + + assertNotNull(nodeMetadata); + assertEquals(nodeMetadata.getId(), actualServer.getServerId()); + assertEquals(nodeMetadata.getHostname(), actualServer.getServerName()); + assertEquals(nodeMetadata.getName(), actualServer.getServerName()); + assertEquals(nodeMetadata.getProviderId(), actualServer.getServerId()); + assertEquals(nodeMetadata.getStatus(), NodeMetadata.Status.RUNNING); + + assertNotNull(nodeMetadata.getOperatingSystem()); + assertEquals(nodeMetadata.getOperatingSystem().getFamily(), OsFamily.LINUX); + assertEquals(nodeMetadata.getOperatingSystem().getDescription(), OsFamily.LINUX.value()); + + assertNotNull(nodeMetadata.getLocation()); + assertEquals(nodeMetadata.getLocation().getId(), actualServer.getDataCenterId()); + assertEquals(nodeMetadata.getLocation().getScope(), LocationScope.REGION); + assertEquals(nodeMetadata.getLocation().getDescription(), actualServer.getDataCenterId()); + + assertNotNull(nodeMetadata.getHardware()); + assertEquals(nodeMetadata.getHardware().getId(), actualServer.getServerId()); + assertNotNull(nodeMetadata.getHardware().getProcessors()); + assertEquals(nodeMetadata.getHardware().getProcessors().size(), 1); + assertEquals(nodeMetadata.getHardware().getProcessors().get(0).getCores(), 2.0); + assertEquals(nodeMetadata.getHardware().getProcessors().get(0).getSpeed(), 0.0); + assertEquals(nodeMetadata.getHardware().getRam(), 1024); + assertNotNull(nodeMetadata.getHardware().getLocation()); + assertEquals(nodeMetadata.getHardware().getLocation().getId(), Server.AvailabilityZone.ZONE_1.value()); + assertEquals(nodeMetadata.getHardware().getLocation().getDescription(), Server.AvailabilityZone.ZONE_1.value()); + assertEquals(nodeMetadata.getHardware().getLocation().getScope(), LocationScope.ZONE); + assertEquals(nodeMetadata.getHardware().getLocation().getParent(), nodeMetadata.getLocation()); + } + + public Server actualServer() { + return Server.describingBuilder() + .dataCenterId("11111-2222-3333-4444-25195ac4515a") + .serverId("47491020-5c6a-1f75-1548-25195ac4515a") + .serverName("LinuxServer") + .cores(2) + .ram(1024) + .creationTime(new SimpleDateFormatDateService().iso8601SecondsDateParse("2013-11-26T06:21:13Z")) + .lastModificationTime(new SimpleDateFormatDateService().iso8601SecondsDateParse("2013-11-27T21:43:15Z")) + .provisioningState(Server.ProvisioningState.AVAILABLE) + .virtualMachineState(Server.VirtualMachineState.RUNNING) + .osType(Server.OSType.LINUX) + .internetAccess(true) + .availabilityZone(Server.AvailabilityZone.ZONE_1) + .build(); + } + + @Test + public void testMapOS() { + ServerToNodeMetadata func = new ServerToNodeMetadata(); + assertEquals(func.mapOS(Server.OSType.LINUX).getFamily(), OsFamily.LINUX); + assertEquals(func.mapOS(Server.OSType.LINUX).getDescription(), OsFamily.LINUX.value()); + + assertEquals(func.mapOS(Server.OSType.WINDOWS).getFamily(), OsFamily.WINDOWS); + assertEquals(func.mapOS(Server.OSType.WINDOWS).getDescription(), OsFamily.WINDOWS.value()); + + assertEquals(func.mapOS(Server.OSType.OTHER).getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(func.mapOS(Server.OSType.OTHER).getDescription(), OsFamily.UNRECOGNIZED.value()); + + assertEquals(func.mapOS(Server.OSType.UNKNOWN).getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(func.mapOS(Server.OSType.UNKNOWN).getDescription(), OsFamily.UNRECOGNIZED.value()); + + assertEquals(func.mapOS(null).getFamily(), OsFamily.UNRECOGNIZED); + assertEquals(func.mapOS(null).getDescription(), OsFamily.UNRECOGNIZED.value()); + } + + @Test + public void testMapStatus() { + ServerToNodeMetadata func = new ServerToNodeMetadata(); + assertEquals(func.mapStatus(BLOCKED), NodeMetadata.Status.PENDING); + assertEquals(func.mapStatus(CRASHED), NodeMetadata.Status.ERROR); + assertEquals(func.mapStatus(NOSTATE), NodeMetadata.Status.UNRECOGNIZED); + assertEquals(func.mapStatus(PAUSED), NodeMetadata.Status.SUSPENDED); + assertEquals(func.mapStatus(RUNNING), NodeMetadata.Status.RUNNING); + assertEquals(func.mapStatus(SHUTDOWN), NodeMetadata.Status.SUSPENDED); + assertEquals(func.mapStatus(SHUTOFF), NodeMetadata.Status.SUSPENDED); + assertEquals(func.mapStatus(UNRECOGNIZED), NodeMetadata.Status.UNRECOGNIZED); + assertEquals(func.mapStatus(null), NodeMetadata.Status.UNRECOGNIZED); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/BasePBResponseHandlerTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/BasePBResponseHandlerTest.java new file mode 100644 index 000000000..5798df310 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/BasePBResponseHandlerTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.easymock.EasyMock; +import org.jclouds.date.DateCodec; +import org.jclouds.date.DateCodecFactory; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.Date; + +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +/** + * Test for {@link BasePBResponseHandler} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "BasePBResponseHandlerTest") +public class BasePBResponseHandlerTest { + + private BasePBResponseHandler handler; + + private Date now; + + @BeforeMethod + public void setUp() { + DateCodecFactory dateCodecFactory = EasyMock.createMock(DateCodecFactory.class); + DateCodec dateCodec = EasyMock.createMock(DateCodec.class); + now = new Date(); + + expect(dateCodec.toDate("2013")).andStubReturn(now); + expect(dateCodecFactory.iso8601()).andStubReturn(dateCodec); + replay(dateCodec, dateCodecFactory); + + handler = new BasePBResponseHandlerImpl(dateCodecFactory); + } + + @Test + public void testTextBufferValue() { + handler.characters(new char[] {' ', 'v', 'a', 'l', 'u', 'e', ' '}, 0, 7); + assertEquals(handler.textBufferValue(), " value "); + + handler.clearTextBuffer(); + assertEquals(handler.textBufferValue(), ""); + } + + @Test + public void testTrimTextBufferValue() { + handler.characters(new char[] {' ', 'v', 'a', 'l', 'u', 'e', ' '}, 0, 6); + assertEquals(handler.trimAndGetTagStrValue(), "value"); + } + + @Test + public void testTextBufferToIntValue() { + handler.characters(new char[] {' ', '1', '2', '3', '4', '5', ' '}, 1, 2); + assertEquals(handler.textBufferToIntValue(), 12); + } + + @Test + public void testTextBufferToBoolValue() { + handler.characters(new char[] {' ', 't', 'r', 'u', 'e', '5', ' '}, 1, 4); + assertTrue(handler.textBufferToBoolValue()); + + handler.characters(new char[]{' ', 'F', 'A', 'L', 'S', 'E', ' '}, 1, 5); + assertFalse(handler.textBufferToBoolValue()); + } + + @Test + public void testTextBufferToDate() { + handler.characters(new char[]{' ', '2', '0', '1', '3', ' '}, 1, 4); + assertEquals(handler.textBufferToIso8601Date(), now); + } + + private class BasePBResponseHandlerImpl extends BasePBResponseHandler { + public BasePBResponseHandlerImpl(DateCodecFactory dateCodecFactory) { + super(dateCodecFactory); + } + + @Override + public String getResult() { + return null; + } + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerRequestBinderTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerRequestBinderTest.java new file mode 100644 index 000000000..92843a38e --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerRequestBinderTest.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import com.google.common.collect.Maps; +import org.jclouds.http.HttpRequest; +import org.jclouds.profitbricks.domain.Server; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.util.HashMap; + +import static org.easymock.EasyMock.*; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Test for {@link CreateServerRequestBinder} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "CreateServerRequestBinderTest") +public class CreateServerRequestBinderTest { + + private CreateServerRequestBinder createServerRequestBinder; + private ServerEnumsToStringMapper mapperMock; + + @BeforeMethod + public void setUp() { + mapperMock = createMock(ServerEnumsToStringMapper.class); + createServerRequestBinder = new CreateServerRequestBinder(mapperMock); + } + + @Test + public void checkAllFieldsAreMapped() { + expect(mapperMock.mapOSType(anyObject(Server.OSType.class))).andStubReturn("OS_TYPE"); + expect(mapperMock.mapAvailabilityZone(anyObject(Server.AvailabilityZone.class))).andStubReturn("ZONE"); + replay(mapperMock); + + HttpRequest request = createRequest(); + + String expectedPayload = "" + + "" + + "11111-2222-3333-4444-25195ac4515a" + + "LinuxServer" + + "2" + + "1024" + + "true" + + "OS_TYPE" + + "ZONE" + + "" + + ""; + + HttpRequest resultRequest = createServerRequestBinder.bindToRequest(request, createParams(maxInfoServer())); + assertNotNull(resultRequest); + assertEquals(resultRequest.getPayload().getRawContent(), expectedPayload); + } + + @Test + public void checkNotEmptyFieldsAreMapped() { + expect(mapperMock.mapOSType(anyObject(Server.OSType.class))).andStubReturn(""); + expect(mapperMock.mapAvailabilityZone(anyObject(Server.AvailabilityZone.class))).andStubReturn(""); + replay(mapperMock); + + HttpRequest request = createRequest(); + + String expectedPayload = "" + + "" + + "2" + + "1024" + + "false" + + "" + + ""; + + HttpRequest resultRequest = createServerRequestBinder.bindToRequest(request, createParams(minInfoServer())); + assertNotNull(resultRequest); + assertEquals(resultRequest.getPayload().getRawContent(), expectedPayload); + } + + private HttpRequest createRequest() { + return HttpRequest.builder().method("POST").endpoint("http://home.local").build(); + } + + private HashMap createParams(Server server) { + HashMap postParams = Maps.newHashMap(); + postParams.put(PBApiRequestParameters.SERVER_ENTITY, server); + return postParams; + } + + public Server minInfoServer() { + return Server.creationBuilder() + .cores(2) + .ram(1024) + .build(); + } + + public Server maxInfoServer() { + return Server.creationBuilder() + .dataCenterId("11111-2222-3333-4444-25195ac4515a") + .serverName("LinuxServer") + .cores(2) + .ram(1024) + .osType(Server.OSType.LINUX) + .internetAccess(true) + .availabilityZone(Server.AvailabilityZone.ZONE_1) + .build(); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerResponseHandlerTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerResponseHandlerTest.java new file mode 100644 index 000000000..6d20f48e4 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/CreateServerResponseHandlerTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +import java.io.InputStream; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Test for {@link CreateServerResponseHandler} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "CreateServerResponseHandlerTest") +public class CreateServerResponseHandlerTest extends BaseHandlerTest { + + @Test + public void testHandlerResult() { + InputStream is = getClass().getResourceAsStream("/servers/createServerResponse.xml"); + + CreateServerResponseHandler handler = injector.getInstance(CreateServerResponseHandler.class); + String actualServerId = factory.create(handler).parse(is); + + assertNotNull(actualServerId); + assertEquals(actualServerId, "8eb5a0df-ddea-4a98-a628-8833dcc9309f"); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandlerTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandlerTest.java new file mode 100644 index 000000000..8c9381b76 --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetAllServersResponseHandlerTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import com.google.common.collect.Lists; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.profitbricks.domain.Server; +import org.testng.annotations.Test; + +import java.io.InputStream; +import java.util.List; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Test for {@link GetAllServersResponseHandler} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "GetAllServersResponseHandlerTest") +public class GetAllServersResponseHandlerTest extends BaseHandlerTest { + + @Test + public void testHandlerResult() { + InputStream is = getClass().getResourceAsStream("/servers/getAllServersResponse.xml"); + + List expectedResult = expectedResult(); + + GetAllServersResponseHandler handler = injector.getInstance(GetAllServersResponseHandler.class); + Set result = factory.create(handler).parse(is); + + assertNotNull(result); + assertEquals(result.size(), 3); + + for (Server expectedServer : expectedResult) { + Server actualServer = findInSet(result, expectedServer.getServerId()); + + assertNotNull(actualServer, errForServer(expectedServer)); + assertEquals(actualServer.getRam(), expectedServer.getRam(), errForServer(expectedServer)); + assertEquals(actualServer.getAvailabilityZone(), expectedServer.getAvailabilityZone(), errForServer(expectedServer)); + assertEquals(actualServer.getCores(), expectedServer.getCores(), errForServer(expectedServer)); + assertEquals(actualServer.getCreationTime(), expectedServer.getCreationTime(), errForServer(expectedServer)); + assertEquals(actualServer.getDataCenterId(), expectedServer.getDataCenterId(), errForServer(expectedServer)); + assertEquals(actualServer.getLastModificationTime(), expectedServer.getLastModificationTime(), errForServer(expectedServer)); + assertEquals(actualServer.getOsType(), expectedServer.getOsType(), errForServer(expectedServer)); + assertEquals(actualServer.getProvisioningState(), expectedServer.getProvisioningState(), errForServer(expectedServer)); + assertEquals(actualServer.getServerName(), expectedServer.getServerName(), errForServer(expectedServer)); + assertEquals(actualServer.getVirtualMachineState(), expectedServer.getVirtualMachineState(), errForServer(expectedServer)); + assertEquals(actualServer.isInternetAccess(), expectedServer.isInternetAccess(), errForServer(expectedServer)); + } + } + + private String errForServer(Server server) { + return "serverId=" + server.getServerId(); + } + + private Server findInSet(Set src, String serverId) { + for (Server server : src) + if (server.getServerId().equals(serverId)) return server; + + return null; + } + + private List expectedResult() { + SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); + + return Lists.newArrayList( + Server.describingBuilder() + .dataCenterId("79046edb-2a50-4d0f-a153-6576ee7d22a6") + .serverId("fd4ffc52-1f2e-4a82-b155-75b2d5e6dd68") + .serverName("server") + .cores(2) + .ram(1024) + .creationTime(dateService.iso8601DateParse("2013-11-26T11:23:47.742Z")) + .lastModificationTime(dateService.iso8601DateParse("2013-11-26T11:23:47.742Z")) + .provisioningState(Server.ProvisioningState.AVAILABLE) + .virtualMachineState(Server.VirtualMachineState.RUNNING) + .osType(Server.OSType.LINUX) + .internetAccess(false) + .availabilityZone(Server.AvailabilityZone.AUTO) + .build(), + + Server.describingBuilder() + .dataCenterId("89046edb-2a50-4d0f-a153-6576ee7d22a7") + .serverId("722694b6-8635-4433-8dea-012860cab5fe") + .serverName("FirstServer") + .cores(1) + .ram(1024) + .creationTime(dateService.iso8601DateParse("2013-11-26T11:23:50.742Z")) + .lastModificationTime(dateService.iso8601DateParse("2013-11-26T11:23:50.742Z")) + .provisioningState(Server.ProvisioningState.INACTIVE) + .virtualMachineState(Server.VirtualMachineState.PAUSED) + .osType(Server.OSType.WINDOWS) + .internetAccess(true) + .availabilityZone(Server.AvailabilityZone.ZONE_1) + .build(), + + Server.describingBuilder() + .dataCenterId("79046edb-2a50-4d0f-a153-6576ee7d22a6") + .serverId("93981076-2511-4aa7-82c0-1e4df0d1737f") + .serverName("server") + .cores(2) + .ram(2048) + .creationTime(dateService.iso8601DateParse("2013-11-26T11:31:35.383Z")) + .lastModificationTime(dateService.iso8601DateParse("2013-11-26T11:31:35.383Z")) + .provisioningState(Server.ProvisioningState.DELETED) + .virtualMachineState(Server.VirtualMachineState.SHUTOFF) + .osType(Server.OSType.OTHER) + .internetAccess(false) + .availabilityZone(Server.AvailabilityZone.ZONE_2) + .build() + ); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetServerResponseHandlerTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetServerResponseHandlerTest.java new file mode 100644 index 000000000..4eb44a51d --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/GetServerResponseHandlerTest.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.profitbricks.domain.Server; +import org.testng.annotations.Test; + +import java.io.InputStream; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +/** + * Test for {@link GetServerResponseHandler} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "GetServerResponseHandlerTest") +public class GetServerResponseHandlerTest extends BaseHandlerTest { + + @Test + public void testHandlerResult() { + InputStream is = getClass().getResourceAsStream("/servers/getServerResponse.xml"); + + Server expectedServer = expectedServer(); + + GetServerResponseHandler handler = injector.getInstance(GetServerResponseHandler.class); + Server actualServer = factory.create(handler).parse(is); + + assertNotNull(actualServer); + + assertNotNull(actualServer); + assertEquals(actualServer.getServerId(), expectedServer.getServerId()); + assertEquals(actualServer.getRam(), expectedServer.getRam()); + assertEquals(actualServer.getAvailabilityZone(), expectedServer.getAvailabilityZone()); + assertEquals(actualServer.getCores(), expectedServer.getCores()); + assertEquals(actualServer.getCreationTime(), expectedServer.getCreationTime()); + assertEquals(actualServer.getDataCenterId(), expectedServer.getDataCenterId()); + assertEquals(actualServer.getLastModificationTime(), expectedServer.getLastModificationTime()); + assertEquals(actualServer.getOsType(), expectedServer.getOsType()); + assertEquals(actualServer.getProvisioningState(), expectedServer.getProvisioningState()); + assertEquals(actualServer.getServerName(), expectedServer.getServerName()); + assertEquals(actualServer.getVirtualMachineState(), expectedServer.getVirtualMachineState()); + assertEquals(actualServer.isInternetAccess(), expectedServer.isInternetAccess()); + } + + private Server expectedServer() { + SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); + + return Server.describingBuilder() + .dataCenterId("79046edb-2a50-4d0f-a153-6576ee7d22a6") + .serverId("93981076-2511-4aa7-82c0-1e4df0d1737f") + .serverName("server") + .cores(2) + .ram(1024) + .creationTime(dateService.iso8601DateParse("2013-11-26T11:31:35.383Z")) + .lastModificationTime(dateService.iso8601DateParse("2013-11-26T11:31:35.383Z")) + .provisioningState(Server.ProvisioningState.AVAILABLE) + .virtualMachineState(Server.VirtualMachineState.RUNNING) + .osType(Server.OSType.WINDOWS) + .internetAccess(false) + .availabilityZone(Server.AvailabilityZone.AUTO) + .build(); + } + +} diff --git a/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapperTest.java b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapperTest.java new file mode 100644 index 000000000..b5fd0dd2d --- /dev/null +++ b/profitbricks-c2/src/test/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapperTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.profitbricks.xml; + +import org.jclouds.profitbricks.domain.Server; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * Test for {@code ServerEnumsToStringMapper} + * + * @author Serj Sintsov + */ +@Test(groups = "unit", testName = "ServerEnumsToStringMapperTest") +public class ServerEnumsToStringMapperTest { + + private ServerEnumsToStringMapper mapper = new ServerEnumsToStringMapper(); + + @Test + public void testMapOsType() { + assertEquals(mapper.mapOSType(null), ""); + assertEquals(mapper.mapOSType(Server.OSType.OTHER), "OTHER"); + assertEquals(mapper.mapOSType(Server.OSType.UNKNOWN), "UNKNOWN"); + assertEquals(mapper.mapOSType(Server.OSType.WINDOWS), "WINDOWS"); + assertEquals(mapper.mapOSType(Server.OSType.LINUX), "LINUX"); + } + + @Test + public void testMapAvailabilityZone() { + assertEquals(mapper.mapAvailabilityZone(null), ""); + assertEquals(mapper.mapAvailabilityZone(Server.AvailabilityZone.AUTO), "AUTO"); + assertEquals(mapper.mapAvailabilityZone(Server.AvailabilityZone.ZONE_1), "ZONE_1"); + assertEquals(mapper.mapAvailabilityZone(Server.AvailabilityZone.ZONE_2), "ZONE_2"); + } + +} diff --git a/profitbricks-c2/src/test/resources/servers/createServerResponse.xml b/profitbricks-c2/src/test/resources/servers/createServerResponse.xml new file mode 100644 index 000000000..8da363a46 --- /dev/null +++ b/profitbricks-c2/src/test/resources/servers/createServerResponse.xml @@ -0,0 +1,12 @@ + + + + + 1264396 + 79046edb-2a50-4d0f-a153-6576ee7d22a6 + 11 + 8eb5a0df-ddea-4a98-a628-8833dcc9309f + + + + \ No newline at end of file diff --git a/profitbricks-c2/src/test/resources/servers/getAllServersResponse.xml b/profitbricks-c2/src/test/resources/servers/getAllServersResponse.xml new file mode 100644 index 000000000..f70425a6a --- /dev/null +++ b/profitbricks-c2/src/test/resources/servers/getAllServersResponse.xml @@ -0,0 +1,51 @@ + + + + + 79046edb-2a50-4d0f-a153-6576ee7d22a6 + 6 + fd4ffc52-1f2e-4a82-b155-75b2d5e6dd68 + server + 2 + 1024 + false + AVAILABLE + RUNNING + 2013-11-26T11:23:47.742Z + 2013-11-26T11:23:47.742Z + LINUX + AUTO + + + 89046edb-2a50-4d0f-a153-6576ee7d22a7 + 6 + 722694b6-8635-4433-8dea-012860cab5fe + FirstServer + 1 + 1024 + true + INACTIVE + PAUSED + 2013-11-26T11:23:50.742Z + 2013-11-26T11:23:50.742Z + WINDOWS + ZONE_1 + + + 79046edb-2a50-4d0f-a153-6576ee7d22a6 + 6 + 93981076-2511-4aa7-82c0-1e4df0d1737f + server + 2 + 2048 + false + DELETED + SHUTOFF + 2013-11-26T11:31:35.383Z + 2013-11-26T11:31:35.383Z + OTHER + ZONE_2 + + + + \ No newline at end of file diff --git a/profitbricks-c2/src/test/resources/servers/getServerResponse.xml b/profitbricks-c2/src/test/resources/servers/getServerResponse.xml new file mode 100644 index 000000000..ee46f8bb0 --- /dev/null +++ b/profitbricks-c2/src/test/resources/servers/getServerResponse.xml @@ -0,0 +1,22 @@ + + + + + 1257559 + 79046edb-2a50-4d0f-a153-6576ee7d22a6 + 9 + 93981076-2511-4aa7-82c0-1e4df0d1737f + server + 2 + 1024 + false + AVAILABLE + RUNNING + 2013-11-26T11:31:35.383Z + 2013-11-26T11:31:35.383Z + WINDOWS + AUTO + + + + \ No newline at end of file From fb84afe12961733318639fe6d38f965072e4a028 Mon Sep 17 00:00:00 2001 From: Serj Sintsov Date: Fri, 29 Nov 2013 18:41:31 +0300 Subject: [PATCH 2/2] profitbricks: doc: add license header --- .../xml/ServerEnumsToStringMapper.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java index 8c845a0b4..e7a9459f6 100644 --- a/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java +++ b/profitbricks-c2/src/main/java/org/jclouds/profitbricks/xml/ServerEnumsToStringMapper.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jclouds.profitbricks.xml; import org.jclouds.profitbricks.domain.Server;