| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.cloudsigma.config; |
| 20 | |
| 21 | import java.util.List; |
| 22 | import java.util.Map; |
| 23 | |
| 24 | import org.jclouds.cloudsigma.CloudSigmaAsyncClient; |
| 25 | import org.jclouds.cloudsigma.CloudSigmaClient; |
| 26 | import org.jclouds.cloudsigma.domain.Device; |
| 27 | import org.jclouds.cloudsigma.domain.Drive; |
| 28 | import org.jclouds.cloudsigma.domain.DriveData; |
| 29 | import org.jclouds.cloudsigma.domain.DriveMetrics; |
| 30 | import org.jclouds.cloudsigma.domain.NIC; |
| 31 | import org.jclouds.cloudsigma.domain.Server; |
| 32 | import org.jclouds.cloudsigma.domain.ServerMetrics; |
| 33 | import org.jclouds.cloudsigma.functions.BaseDriveToMap; |
| 34 | import org.jclouds.cloudsigma.functions.DriveDataToMap; |
| 35 | import org.jclouds.cloudsigma.functions.MapToDevices; |
| 36 | import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; |
| 37 | import org.jclouds.cloudsigma.functions.MapToDriveMetrics; |
| 38 | import org.jclouds.cloudsigma.functions.MapToNICs; |
| 39 | import org.jclouds.cloudsigma.functions.MapToServerMetrics; |
| 40 | import org.jclouds.cloudsigma.functions.ServerToMap; |
| 41 | import org.jclouds.cloudsigma.handlers.CloudSigmaErrorHandler; |
| 42 | import org.jclouds.http.HttpErrorHandler; |
| 43 | import org.jclouds.http.RequiresHttp; |
| 44 | import org.jclouds.http.annotation.ClientError; |
| 45 | import org.jclouds.http.annotation.Redirection; |
| 46 | import org.jclouds.http.annotation.ServerError; |
| 47 | import org.jclouds.rest.ConfiguresRestClient; |
| 48 | import org.jclouds.rest.config.RestClientModule; |
| 49 | |
| 50 | import com.google.common.base.Function; |
| 51 | import com.google.inject.TypeLiteral; |
| 52 | |
| 53 | /** |
| 54 | * Configures the CloudSigma connection. |
| 55 | * |
| 56 | * @author Adrian Cole |
| 57 | */ |
| 58 | @RequiresHttp |
| 59 | @ConfiguresRestClient |
| 60 | public class CloudSigmaRestClientModule extends RestClientModule<CloudSigmaClient, CloudSigmaAsyncClient> { |
| 61 | |
| 62 | public CloudSigmaRestClientModule() { |
| 63 | super(CloudSigmaClient.class, CloudSigmaAsyncClient.class); |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | protected void bindErrorHandlers() { |
| 68 | bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(CloudSigmaErrorHandler.class); |
| 69 | bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CloudSigmaErrorHandler.class); |
| 70 | bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CloudSigmaErrorHandler.class); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void configure() { |
| 75 | super.configure(); |
| 76 | bind(new TypeLiteral<Function<Drive, Map<String, String>>>() { |
| 77 | }).to(BaseDriveToMap.class); |
| 78 | bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() { |
| 79 | }).to(DriveDataToMap.class); |
| 80 | bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() { |
| 81 | }).to(MapToNICs.class); |
| 82 | bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() { |
| 83 | }).to(MapToDevices.class); |
| 84 | bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() { |
| 85 | }).to(MapToDriveMetrics.class); |
| 86 | bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() { |
| 87 | }).to(MapToServerMetrics.class); |
| 88 | bind(new TypeLiteral<Function<Device, String>>() { |
| 89 | }).to(DeviceToId.class); |
| 90 | bind(new TypeLiteral<Function<Server, Map<String, String>>>() { |
| 91 | }).to(ServerToMap.class); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | protected void bindRetryHandlers() { |
| 96 | // TODO |
| 97 | } |
| 98 | |
| 99 | } |