Skip to content
Permalink
Browse files
[JCLOUDS-1430] - add more features
- add securitygroup-api
- add keypair-api
- add tag-api
- refactor paginations
- refactor tagOptions
  • Loading branch information
andreaturli committed Jul 31, 2018
1 parent d74d7f6 commit a5dbf0065d8fa8cabcaf020b7c10fe2f7ccf8d6a
Showing 47 changed files with 2,304 additions and 110 deletions.
@@ -18,6 +18,9 @@

import org.jclouds.aliyun.ecs.features.ImageApi;
import org.jclouds.aliyun.ecs.features.RegionAndZoneApi;
import org.jclouds.aliyun.ecs.features.SecurityGroupApi;
import org.jclouds.aliyun.ecs.features.SshKeyPairApi;
import org.jclouds.aliyun.ecs.features.TagApi;
import org.jclouds.rest.annotations.Delegate;

import java.io.Closeable;
@@ -30,4 +33,13 @@ public interface ECSComputeServiceApi extends Closeable {
@Delegate
RegionAndZoneApi regionAndZoneApi();

@Delegate
SecurityGroupApi securityGroupApi();

@Delegate
SshKeyPairApi sshKeyPairApi();

@Delegate
TagApi tagApi();

}
@@ -33,21 +33,21 @@ public abstract class Image {
"ImageOwnerAlias", "Progress", "IsSupportCloudinit", "Usage", "CreationTime", "Tags",
"ImageVersion", "Status", "ImageName", "IsSupportIoOptimized", "IsSelfShared", "IsCopied",
"IsSubscribed", "Platform", "Size"})
public static Image create(String imageId, String description, String productCode, String osType,
public static Image create(String id, String description, String productCode, String osType,
String architecture, String osName, Map<String, List<DiskDeviceMapping>> diskDeviceMappings,
String imageOwnerAlias, String progress, Boolean isSupportCloudinit, String usage, Date creationTime,
Map<String, List<Tag>> tags, String imageVersion, String status, String imageName,
Map<String, List<Tag>> tags, String imageVersion, String status, String name,
Boolean isSupportIoOptimized, Boolean isSelfShared, Boolean isCopied, Boolean isSubscribed, String platform,
String size) {
return new AutoValue_Image(imageId, description, productCode, osType, architecture, osName,
return new AutoValue_Image(id, description, productCode, osType, architecture, osName,
diskDeviceMappings == null ?
ImmutableMap.<String, List<DiskDeviceMapping>>of() :
ImmutableMap.copyOf(diskDeviceMappings), imageOwnerAlias, progress, isSupportCloudinit, usage,
creationTime, tags == null ? ImmutableMap.<String, List<Tag>>of() : ImmutableMap.copyOf(tags), imageVersion,
status, imageName, isSupportIoOptimized, isSelfShared, isCopied, isSubscribed, platform, size);
status, name, isSupportIoOptimized, isSelfShared, isCopied, isSubscribed, platform, size);
}

public abstract String imageId();
public abstract String id();

public abstract String description();

@@ -77,7 +77,7 @@ public static Image create(String imageId, String description, String productCod

public abstract String status();

public abstract String imageName();
public abstract String name();

public abstract Boolean isSupportIoOptimizeds();

@@ -0,0 +1,41 @@
/*
* 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.aliyun.ecs.domain;

import com.google.common.base.Enums;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;

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

/**
* IP protocol. Not case sensitive. Optional values:
* icmp
* gre
* tcp
* udp
* all: Support four protocols at the same time
*/
public enum IpProtocol {
ICMP, GRE, TCP, UDP, ALL;

public static IpProtocol fromValue(String value) {
Optional<IpProtocol> ipProtocol = Enums.getIfPresent(IpProtocol.class, value.toUpperCase());
checkArgument(ipProtocol.isPresent(), "Expected one of %s but was %s", Joiner.on(',').join(IpProtocol.values()), value);
return ipProtocol.get();
}
}
@@ -16,18 +16,25 @@
*/
package org.jclouds.aliyun.ecs.domain;

import org.jclouds.aliyun.ecs.domain.internal.PaginatedCollection;
import com.google.auto.value.AutoValue;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;

import java.beans.ConstructorProperties;
import java.util.Map;
@AutoValue
public abstract class KeyPair {

/**
* A collection of Image
*/
public class Images extends PaginatedCollection<Image> {
KeyPair() {}

@ConstructorProperties({ "Images", "PageNumber", "TotalCount", "PageSize", "RegionId", "RequestId" })
public Images(Map<String, Iterable<Image>> content, Integer pageNumber, Integer totalCount, Integer pageSize, String regionId, String requestId) {
super(content, pageNumber, totalCount, pageSize, regionId, requestId);
@SerializedNames({ "KeyPairName", "KeyPairFingerPrint", "PrivateKeyBody" })
public static KeyPair create(String name, String keyPairFingerPrint, String privateKeyBody) {
return new AutoValue_KeyPair(name, keyPairFingerPrint, privateKeyBody);
}

public abstract String name();

public abstract String keyPairFingerPrint();

@Nullable
public abstract String privateKeyBody();

}
@@ -0,0 +1,76 @@
/*
* 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.aliyun.ecs.domain;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

import java.beans.ConstructorProperties;

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

public class KeyPairRequest extends Request {

private final String keyPairName;
private final String keyPairFingerPrint;
private final String privateKeyBody;

@ConstructorProperties({ "RequestId", "KeyPairName", "KeyPairFingerPrint", "PrivateKeyBody" })
public KeyPairRequest(String requestId, String keyPairName, String keyPairFingerPrint, String privateKeyBody) {
super(requestId);
this.keyPairName = checkNotNull(keyPairName, "name");
this.keyPairFingerPrint = checkNotNull(keyPairFingerPrint, "keyPairFingerPrint");
this.privateKeyBody = checkNotNull(privateKeyBody, "privateKeyBody");
}

public String getKeyPairName() {
return keyPairName;
}

public String getKeyPairFingerPrint() {
return keyPairFingerPrint;
}

public String getPrivateKeyBody() {
return privateKeyBody;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
KeyPairRequest that = (KeyPairRequest) o;
return Objects.equal(keyPairName, that.keyPairName) &&
Objects.equal(keyPairFingerPrint, that.keyPairFingerPrint) &&
Objects.equal(privateKeyBody, that.privateKeyBody);
}

@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), keyPairName, keyPairFingerPrint, privateKeyBody);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("name", keyPairName)
.add("keyPairFingerPrint", keyPairFingerPrint)
.add("privateKeyBody", privateKeyBody)
.toString();
}
}
@@ -0,0 +1,110 @@
/*
* 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.aliyun.ecs.domain;

import com.google.auto.value.AutoValue;
import com.google.common.base.Enums;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import org.jclouds.json.SerializedNames;

import java.util.Date;

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

@AutoValue
public abstract class Permission {

public enum NicType {
INTERNET, INTRANET;

public static NicType fromValue(String value) {
Optional<NicType> nicType = Enums.getIfPresent(NicType.class, value.toUpperCase());
checkArgument(nicType.isPresent(), "Expected one of %s but was %s", Joiner.on(',').join(NicType.values()), value);
return nicType.get();
}
}

public enum Policy {
ACCEPT, DROP;

public static Policy fromValue(String value) {
Optional<Policy> policy = Enums.getIfPresent(Policy.class, value.toUpperCase());
checkArgument(policy.isPresent(), "Expected one of %s but was %s", Joiner.on(',').join(Policy.values()), value);
return policy.get();
}
}

public enum Direction {
EGRESS, ALL;

public static Direction fromValue(String value) {
Optional<Direction> direction = Enums.getIfPresent(Direction.class, value.toUpperCase());
checkArgument(direction.isPresent(), "Expected one of %s but was %s", Joiner.on(',').join(Direction.values()), value);
return direction.get();
}
}

Permission() {}

@SerializedNames({"SourceCidrIp", "DestCidrIp", "Description", "NicType",
"DestGroupName", "PortRange", "DestGroupId", "Direction", "Priority",
"IpProtocol", "SourceGroupOwnerAccount", "Policy", "CreateTime",
"SourceGroupId", "DestGroupOwnerAccount", "SourceGroupName"})
public static Permission create(String sourceCidrIp, String destCidrIp, String description, NicType nicType,
String destGroupName, String portRange, String destGroupId, Direction direction,
String priority,
IpProtocol ipProtocol, String sourceGroupOwnerAccount, Policy policy,
Date createTime, String sourceGroupId, String destGroupOwnerAccount, String sourceGroupName) {
return new AutoValue_Permission(sourceCidrIp, destCidrIp, description, nicType, destGroupName, portRange,
destGroupId, direction, priority, ipProtocol, sourceGroupOwnerAccount, policy, createTime, sourceGroupId,
destGroupOwnerAccount, sourceGroupName);
}

public abstract String sourceCidrIp();

public abstract String destCidrIp();

public abstract String description();

public abstract NicType nicType();

public abstract String destGroupName();

public abstract String portRange();

public abstract String destGroupId();

public abstract Direction direction();

public abstract String priority();

public abstract IpProtocol ipProtocol();

public abstract String sourceGroupOwnerAccount();

public abstract Policy policy();

public abstract Date createTime();

public abstract String sourceGroupId();

public abstract String destGroupOwnerAccount();

public abstract String sourceGroupName();

}
@@ -25,11 +25,11 @@ public abstract class Region {
Region() {}

@SerializedNames({ "RegionId", "LocalName" })
public static Region create(String regionId, String localName) {
return new AutoValue_Region(regionId, localName);
public static Region create(String id, String localName) {
return new AutoValue_Region(id, localName);
}

public abstract String regionId();
public abstract String id();

public abstract String localName();

@@ -0,0 +1,58 @@
/*
* 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.aliyun.ecs.domain;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

import java.beans.ConstructorProperties;

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

public class Request {

private final String requestId;

@ConstructorProperties({ "RequestId" })
public Request(String requestId) {
this.requestId = checkNotNull(requestId, "requestId");
}

public String getRequestId() {
return requestId;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Request request = (Request) o;
return Objects.equal(requestId, request.requestId);
}

@Override
public int hashCode() {
return Objects.hashCode(requestId);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("requestId", requestId).toString();
}
}

0 comments on commit a5dbf00

Please sign in to comment.