Skip to content
Permalink
Browse files
- Adding structure for Dimension Data CloudControl API JClouds implem…
…entation

- Adding single API for user account retrieval, with mock and live tests
- Adding HTTP request filter that adds organization value to API request paths
  • Loading branch information
John Clarke authored and nacx committed Mar 24, 2017
1 parent 8054a59 commit 6e5082f71c6eac9749826b76d011b4770500c023
Showing 21 changed files with 1,012 additions and 150 deletions.
@@ -0,0 +1,28 @@
/*
* 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.dimensiondata.cloudcontrol;

import org.jclouds.dimensiondata.cloudcontrol.features.AccountApi;
import org.jclouds.rest.annotations.Delegate;

import java.io.Closeable;

public interface DimensionDataCloudControlApi extends Closeable {

@Delegate
AccountApi getAccountApi();
}
@@ -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.dimensiondata.cloudcontrol;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlHttpApiModule;
import org.jclouds.dimensiondata.cloudcontrol.config.DimensionDataCloudControlParserModule;
import org.jclouds.rest.internal.BaseHttpApiMetadata;

import java.net.URI;

import static org.jclouds.reflect.Reflection2.typeToken;

public class DimensionDataCloudControlApiMetadata extends BaseHttpApiMetadata<DimensionDataCloudControlApi> {

@Override
public Builder toBuilder() {
return new Builder().fromApiMetadata(this);
}

public DimensionDataCloudControlApiMetadata() {
this(new Builder());
}

protected DimensionDataCloudControlApiMetadata(Builder builder) {
super(builder);
}

public static class Builder extends BaseHttpApiMetadata.Builder<DimensionDataCloudControlApi, Builder> {

protected Builder() {
id("dimensiondata-cloudcontrol").name("DimensionData CloudControl API").identityName("user name")
.credentialName("user password")
.documentation(URI.create("http://www.dimensiondata.com/en-US/Solutions/Cloud"))
.defaultEndpoint("https://api-REGION.dimensiondata.com/").version("2.4")
.defaultProperties(DimensionDataCloudControlApiMetadata.defaultProperties())
.view(typeToken(ComputeServiceContext.class)).defaultModules(
ImmutableSet.<Class<? extends Module>>builder().add(DimensionDataCloudControlHttpApiModule.class)
.add(DimensionDataCloudControlParserModule.class).build());
}

@Override
public DimensionDataCloudControlApiMetadata build() {
return new DimensionDataCloudControlApiMetadata(this);
}

@Override
protected Builder self() {
return this;
}

@Override
public Builder fromApiMetadata(ApiMetadata in) {
return this;
}
}
}
@@ -0,0 +1,75 @@
/*
* 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.dimensiondata.cloudcontrol;

import com.google.auto.service.AutoService;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.internal.BaseProviderMetadata;

import java.net.URI;
import java.util.Properties;

/**
* Implementation of {@link ProviderMetadata} for DimensionData CloudController.
*/
@AutoService(ProviderMetadata.class)
public class DimensionDataCloudControlProviderMetadata extends BaseProviderMetadata {

public static Builder builder() {
return new Builder();
}

@Override
public Builder toBuilder() {
return builder().fromProviderMetadata(this);
}

public DimensionDataCloudControlProviderMetadata() {
super(builder());
}

public DimensionDataCloudControlProviderMetadata(Builder builder) {
super(builder);
}

public static Properties defaultProperties() {
Properties properties = DimensionDataCloudControlApiMetadata.defaultProperties();
return properties;
}

public static class Builder extends BaseProviderMetadata.Builder {

protected Builder() {
id("dimensiondata-cloudcontrol").name("DimensionData Cloud Control")
.apiMetadata(new DimensionDataCloudControlApiMetadata())
.homepage(URI.create("https://na-cloud.dimensiondata.com/"))
.console(URI.create("https://na-cloud.dimensiondata.com/")).endpoint("https://api-na.dimensiondata.com/")
.defaultProperties(DimensionDataCloudControlProviderMetadata.defaultProperties());
}

@Override
public DimensionDataCloudControlProviderMetadata build() {
return new DimensionDataCloudControlProviderMetadata(this);
}

@Override
public Builder fromProviderMetadata(ProviderMetadata in) {
super.fromProviderMetadata(in);
return this;
}
}
}
@@ -0,0 +1,59 @@
/*
* 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.dimensiondata.cloudcontrol.config;

import com.google.common.base.Supplier;
import com.google.inject.Provides;
import org.jclouds.collect.Memoized;
import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
import org.jclouds.dimensiondata.cloudcontrol.handlers.DimensionDataCloudControlErrorHandler;
import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.config.HttpApiModule;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;

import javax.inject.Named;
import javax.inject.Singleton;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;

@ConfiguresHttpApi
public class DimensionDataCloudControlHttpApiModule extends HttpApiModule<DimensionDataCloudControlApi> {

@Override
protected void bindErrorHandlers() {
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(DimensionDataCloudControlErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(DimensionDataCloudControlErrorHandler.class);
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(DimensionDataCloudControlErrorHandler.class);
}

@Provides
@Singleton
@Memoized
public final Supplier<String> getOrganisationIdForAccount(AtomicReference<AuthorizationException> authException,
@Named(PROPERTY_SESSION_INTERVAL) long seconds, DimensionDataCloudControlApi api) {
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier
.create(authException, new OrganisationIdForAccount(api), seconds, TimeUnit.SECONDS);
}

}
@@ -0,0 +1,27 @@
/*
* 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.dimensiondata.cloudcontrol.config;

import com.google.inject.AbstractModule;

public class DimensionDataCloudControlParserModule extends AbstractModule {

@Override
protected void configure() {
}

}
@@ -0,0 +1,43 @@
/*
* 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.dimensiondata.cloudcontrol.config;

import com.google.common.base.Supplier;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
import org.jclouds.dimensiondata.cloudcontrol.domain.Account;
import org.jclouds.dimensiondata.cloudcontrol.features.AccountApi;

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

@Singleton
public class OrganisationIdForAccount implements Supplier<String> {

private final AccountApi api;

@Inject
OrganisationIdForAccount(DimensionDataCloudControlApi api) {
this.api = api.getAccountApi();
}

@Override
public String get() {
Account account = checkNotNull(api.getMyAccount(), "account");
return account.organization().id();
}
}

0 comments on commit 6e5082f

Please sign in to comment.