Skip to content

Commit

Permalink
#78 update CoreCreateLoadBalancerRequestDto, add LoadBalancerPayType
Browse files Browse the repository at this point in the history
  • Loading branch information
HoweChen committed May 14, 2020
1 parent ad8813a commit e3b5447
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.aliyuncs.slb.model.v20140515.CreateLoadBalancerRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.webank.wecube.plugins.alicloud.common.PluginException;
import com.webank.wecube.plugins.alicloud.dto.CoreRequestInputDto;
import com.webank.wecube.plugins.alicloud.dto.PluginSdkInputBridge;
import com.webank.wecube.plugins.alicloud.service.loadBalancer.LoadBalancerPayType;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
Expand All @@ -15,14 +18,6 @@
*/
public class CoreCreateLoadBalancerRequestDto extends CoreRequestInputDto implements PluginSdkInputBridge<CreateLoadBalancerRequest> {

@Override
public void adaptToAliCloud() {
if (!StringUtils.isEmpty(this.getAddressType()) && StringUtils.equalsIgnoreCase(AddressType.internet.toString(), this.getAddressType())) {
this.setAddress(null);
this.setVSwitchId(null);
}
}

private String loadBalancerId;
private String loadBalancerProtocol;

Expand Down Expand Up @@ -278,6 +273,28 @@ public String toString() {
.toString();
}

@Override
public void adaptToAliCloud() throws PluginException {
if (!StringUtils.isEmpty(this.getAddressType()) && StringUtils.equalsIgnoreCase(AddressType.internet.toString(), this.getAddressType())) {
this.setAddress(null);
this.setVSwitchId(null);
}

if (StringUtils.isNotEmpty(payType)) {
if (EnumUtils.isValidEnumIgnoreCase(LoadBalancerPayType.class, payType)) {
payType = EnumUtils.getEnumIgnoreCase(LoadBalancerPayType.class, payType).toString();
} else {
if (StringUtils.equalsIgnoreCase("postpaid", payType)) {
payType = LoadBalancerPayType.PayOnDemand.toString();
} else if (StringUtils.equalsIgnoreCase("prepaid", payType)) {
payType = LoadBalancerPayType.PrePay.toString();
} else {
throw new PluginException(String.format("Invalid given payType: [%s]", payType));
}
}
}
}

private enum AddressType {
// internet
internet,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.webank.wecube.plugins.alicloud.service.loadBalancer;

public enum LoadBalancerPayType {
// pay on demand
PayOnDemand,
// pre pay
PrePay
}

0 comments on commit e3b5447

Please sign in to comment.