From 980a550119d7cefa1aa33a36fd3e8663a77d4aa0 Mon Sep 17 00:00:00 2001 From: wuchen Date: Tue, 14 Jul 2020 15:53:40 +0800 Subject: [PATCH 1/3] release 1.0.24 code --- connectors/http-connector/pom.xml | 2 +- connectors/httpclient/pom.xml | 2 +- connectors/jersey2/pom.xml | 2 +- connectors/okhttp/pom.xml | 2 +- connectors/pom.xml | 2 +- connectors/resteasy/pom.xml | 2 +- core-functional-test/pom.xml | 2 +- core-integration-test/pom.xml | 2 +- core-sample/pom.xml | 2 +- core-test/pom.xml | 2 +- .../cloudeye/CloudEyeAlarmServiceTest.java | 20 ++- core/pom.xml | 2 +- .../api/cloudeye/AlarmService.java | 9 +- .../cloudeye/domain/CloudEyeAlarmAction.java | 6 +- .../domain/CloudEyeAlarmCondition.java | 10 +- .../domain/CloudEyeCreateAlarmReq.java | 74 ++++++++++ .../cloudeye/domain/CloudEyeMetric.java | 7 + .../domain/CloudEyeMetricDemension.java | 6 +- .../internal/CloudEyeAlarmServiceImpl.java | 9 +- .../v1/contants/InterruptionPolicyEnum.java | 13 ++ .../ecs/v1/domain/ServerExtendParam.java | 131 ++++++++++++++++-- .../v1_1/contants/InterruptionPolicyEnum.java | 13 ++ .../ecs/v1_1/domain/ServerExtendParam.java | 29 ++++ distribution/pom.xml | 2 +- pom.xml | 2 +- 25 files changed, 324 insertions(+), 29 deletions(-) create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeCreateAlarmReq.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/contants/InterruptionPolicyEnum.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/contants/InterruptionPolicyEnum.java diff --git a/connectors/http-connector/pom.xml b/connectors/http-connector/pom.xml index 90c5e6f..2cea86c 100644 --- a/connectors/http-connector/pom.xml +++ b/connectors/http-connector/pom.xml @@ -20,7 +20,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.23 + 1.0.24 OpenStack4j HttpURL Connector openstack4j-http-connector diff --git a/connectors/httpclient/pom.xml b/connectors/httpclient/pom.xml index 58ebe32..00323c4 100644 --- a/connectors/httpclient/pom.xml +++ b/connectors/httpclient/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.23 + 1.0.24 4.0.0 openstack4j-httpclient diff --git a/connectors/jersey2/pom.xml b/connectors/jersey2/pom.xml index 5bd16f0..0c1dd76 100644 --- a/connectors/jersey2/pom.xml +++ b/connectors/jersey2/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.23 + 1.0.24 4.0.0 openstack4j-jersey2 diff --git a/connectors/okhttp/pom.xml b/connectors/okhttp/pom.xml index b25dd7e..e8e34c5 100644 --- a/connectors/okhttp/pom.xml +++ b/connectors/okhttp/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.23 + 1.0.24 4.0.0 openstack4j-okhttp diff --git a/connectors/pom.xml b/connectors/pom.xml index e3a5e6b..a348433 100644 --- a/connectors/pom.xml +++ b/connectors/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 4.0.0 com.huawei.openstack4j.connectors diff --git a/connectors/resteasy/pom.xml b/connectors/resteasy/pom.xml index 3b078c8..1110969 100644 --- a/connectors/resteasy/pom.xml +++ b/connectors/resteasy/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.23 + 1.0.24 4.0.0 openstack4j-resteasy diff --git a/core-functional-test/pom.xml b/core-functional-test/pom.xml index 0474bbf..13aa7b0 100644 --- a/core-functional-test/pom.xml +++ b/core-functional-test/pom.xml @@ -4,7 +4,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 openstack4j-core-functional-test OpenStack4j Core Functional Test Cases diff --git a/core-integration-test/pom.xml b/core-integration-test/pom.xml index 48f97c2..a13ad80 100644 --- a/core-integration-test/pom.xml +++ b/core-integration-test/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 4.0.0 openstack4j-core-integration-test diff --git a/core-sample/pom.xml b/core-sample/pom.xml index d98df14..cf33824 100644 --- a/core-sample/pom.xml +++ b/core-sample/pom.xml @@ -4,7 +4,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 openstack-core-sample OpenStack4j Sample diff --git a/core-test/pom.xml b/core-test/pom.xml index e2b186b..b71f604 100644 --- a/core-test/pom.xml +++ b/core-test/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 4.0.0 openstack4j-core-test diff --git a/core-test/src/main/java/com/huawei/openstack4j/api/cloudeye/CloudEyeAlarmServiceTest.java b/core-test/src/main/java/com/huawei/openstack4j/api/cloudeye/CloudEyeAlarmServiceTest.java index a977767..b05dd5b 100644 --- a/core-test/src/main/java/com/huawei/openstack4j/api/cloudeye/CloudEyeAlarmServiceTest.java +++ b/core-test/src/main/java/com/huawei/openstack4j/api/cloudeye/CloudEyeAlarmServiceTest.java @@ -19,8 +19,11 @@ import static org.testng.Assert.assertNotNull; import static org.testng.AssertJUnit.assertTrue; +import java.util.ArrayList; import java.util.List; +import com.huawei.openstack4j.model.cloudeye.AlarmType; +import com.huawei.openstack4j.openstack.cloudeye.domain.*; import org.testng.annotations.Test; import com.huawei.openstack4j.api.AbstractTest; @@ -30,7 +33,7 @@ import com.huawei.openstack4j.model.common.ActionResponse; import com.huawei.openstack4j.openstack.cloudeye.internal.AlarmFilterOptions; -@Test(groups = "cloudeye", suiteName = "cloudeye/Alarms") + @Test(groups = "cloudeye", suiteName = "cloudeye/Alarms") public class CloudEyeAlarmServiceTest extends AbstractTest { private static final String JSON_ALARMS = "/cloudeye/list_alarms.json"; public static final String ALARM_ID = "al1483387711418ZNpR8DX3g"; @@ -88,5 +91,20 @@ public void deleteAlarmTest() throws Exception { assertTrue(ptrRestoreActionResponse.isSuccess()); } + public void createAlarmTest() throws Exception { + CloudEyeMetricDemension dimension = new CloudEyeMetricDemension("instance_id", "1234567899_id"); + List dimensions = new ArrayList<>(); + dimensions.add(dimension); + CloudEyeMetric metric = new CloudEyeMetric("cpu_util", "%", "SYS.ECS", dimensions); + CloudEyeAlarmCondition condition = new CloudEyeAlarmCondition(300, "average", ">", 12, "%", 3); + CloudEyeAlarmAction action = new CloudEyeAlarmAction(AlarmType.NOTIFICATION, new ArrayList()); + List actions = new ArrayList<>(); + actions.add(action); + CloudEyeCreateAlarmReq alarm = new CloudEyeCreateAlarmReq("alarm_test", "alarm_desc", metric, condition, actions, actions, + actions, true, false, 2); + + ActionResponse ptrRestoreActionResponse = osv3().cloudEye().alarms().create(alarm); + assertTrue(ptrRestoreActionResponse.isSuccess()); + } } diff --git a/core/pom.xml b/core/pom.xml index da0be3d..919e2ef 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -20,7 +20,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 4.0.0 openstack4j-core diff --git a/core/src/main/java/com/huawei/openstack4j/api/cloudeye/AlarmService.java b/core/src/main/java/com/huawei/openstack4j/api/cloudeye/AlarmService.java index 531e47f..1708e9f 100644 --- a/core/src/main/java/com/huawei/openstack4j/api/cloudeye/AlarmService.java +++ b/core/src/main/java/com/huawei/openstack4j/api/cloudeye/AlarmService.java @@ -20,10 +20,17 @@ import com.huawei.openstack4j.common.RestService; import com.huawei.openstack4j.model.cloudeye.Alarm; import com.huawei.openstack4j.model.common.ActionResponse; +import com.huawei.openstack4j.openstack.cloudeye.domain.CloudEyeCreateAlarmReq; import com.huawei.openstack4j.openstack.cloudeye.internal.AlarmFilterOptions; public interface AlarmService extends RestService { - + + /** + * @param alarm The alarm info for creating + * @return + */ + ActionResponse create(CloudEyeCreateAlarmReq alarm); + /** * list alarm * @return diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmAction.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmAction.java index b649ed2..d9fdff4 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmAction.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmAction.java @@ -28,11 +28,15 @@ @ToString @Builder(toBuilder = true) @NoArgsConstructor -@AllArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public class CloudEyeAlarmAction implements AlarmAction{ private static final long serialVersionUID = 5604518526573924452L; AlarmType type; List notificationlist; + + public CloudEyeAlarmAction(AlarmType type, List notificationlist) { + this.type = type; + this.notificationlist = notificationlist; + } } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmCondition.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmCondition.java index 14e10e3..82f445d 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmCondition.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeAlarmCondition.java @@ -26,7 +26,6 @@ @ToString @Builder(toBuilder = true) @NoArgsConstructor -@AllArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public class CloudEyeAlarmCondition implements Condition { private static final long serialVersionUID = 5719142668031530589L; @@ -37,5 +36,14 @@ public class CloudEyeAlarmCondition implements Condition { Number value; String unit; Integer count; + + public CloudEyeAlarmCondition (Integer period, String filter, String comparisonOperator, Number value, String unit, Integer count) { + this.period = period; + this.filter = filter; + this.comparisonOperator = comparisonOperator; + this.value = value; + this.unit = unit; + this.count = count; + } } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeCreateAlarmReq.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeCreateAlarmReq.java new file mode 100644 index 0000000..671b9ef --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeCreateAlarmReq.java @@ -0,0 +1,74 @@ + /******************************************************************************* + * Copyright 2018 Huawei Technologies Co.,Ltd. + * + * Licensed 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 com.huawei.openstack4j.openstack.cloudeye.domain; + + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + import com.fasterxml.jackson.annotation.JsonProperty; + import com.huawei.openstack4j.model.ModelEntity; + import lombok.*; + + import java.util.List; + + @Getter + @ToString + @Builder(toBuilder = true) + @NoArgsConstructor + @JsonIgnoreProperties(ignoreUnknown = true) + public class CloudEyeCreateAlarmReq implements ModelEntity { + private static final long serialVersionUID = -1524440551458098127L; + + @JsonProperty("alarm_name") + String alarmName; + + @JsonProperty("alarm_description") + String alarmDescription; + + CloudEyeMetric metric; + + CloudEyeAlarmCondition condition; + + @JsonProperty("alarm_actions") + List alarmActions; + + @JsonProperty("insufficientdata_actions") + List insufficientdataActions; + + @JsonProperty("ok_actions") + List okActions; + + @JsonProperty("alarm_enabled") + Boolean alarmEnabled; + + @JsonProperty("alarm_action_enabled") + Boolean alarmActionEnabled; + + @JsonProperty("alarm_level") + Integer alarmLevel; + + public CloudEyeCreateAlarmReq (String alarmName, String alarmDescription, CloudEyeMetric metric, CloudEyeAlarmCondition condition, List alarmActions, List insufficientdataActions, + List okActions, Boolean alarmEnabled, Boolean alarmActionEnabled, Integer alarmLevel) { + this.alarmName = alarmName; + this.alarmDescription = alarmDescription; + this.metric = metric; + this.condition = condition; + this.alarmActions = alarmActions; + this.insufficientdataActions = insufficientdataActions; + this.okActions = okActions; + this.alarmActionEnabled = alarmActionEnabled; + this.alarmEnabled = alarmEnabled; + this.alarmLevel = alarmLevel; + } + } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetric.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetric.java index 2515bba..3f48021 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetric.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetric.java @@ -68,4 +68,11 @@ public List value() { return list; } } + + public CloudEyeMetric(String metricName, String unit, String namespace, List dimensions) { + this.metricName = metricName; + this.unit = unit; + this.namespace = namespace; + this.dimensions = dimensions; + } } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetricDemension.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetricDemension.java index 59fd82e..b1a5dca 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetricDemension.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/domain/CloudEyeMetricDemension.java @@ -24,11 +24,15 @@ @ToString @Builder(toBuilder = true) @NoArgsConstructor -@AllArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) public class CloudEyeMetricDemension implements MetricDimensions { private static final long serialVersionUID = -959253863059879414L; String name; String value; + + public CloudEyeMetricDemension(String name, String value) { + this.name = name; + this.value = value; + } } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/internal/CloudEyeAlarmServiceImpl.java b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/internal/CloudEyeAlarmServiceImpl.java index 6c157f5..def6c58 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/internal/CloudEyeAlarmServiceImpl.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/cloudeye/internal/CloudEyeAlarmServiceImpl.java @@ -26,8 +26,15 @@ import com.huawei.openstack4j.model.cloudeye.Alarm; import com.huawei.openstack4j.model.common.ActionResponse; import com.huawei.openstack4j.openstack.cloudeye.domain.CloudEyeAlarm; +import com.huawei.openstack4j.openstack.cloudeye.domain.CloudEyeCreateAlarmReq; -public class CloudEyeAlarmServiceImpl extends BaseCloudEyeServices implements AlarmService { + public class CloudEyeAlarmServiceImpl extends BaseCloudEyeServices implements AlarmService { + + @Override + public ActionResponse create(CloudEyeCreateAlarmReq alarm) { + checkNotNull(alarm); + return postWithResponse(PATH_ALARMS).entity(alarm).execute(); + } @Override public List list() { diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/contants/InterruptionPolicyEnum.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/contants/InterruptionPolicyEnum.java new file mode 100644 index 0000000..983de29 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/contants/InterruptionPolicyEnum.java @@ -0,0 +1,13 @@ +package com.huawei.openstack4j.openstack.ecs.v1.contants; + +public enum InterruptionPolicyEnum { + /** + * Enum IMMEDIATE for value: "immediate" + */ + immediate, + /** + * Enum DELAY for value: "delay" + */ + delay + +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerExtendParam.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerExtendParam.java index 43cbbf5..c324129 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerExtendParam.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerExtendParam.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import com.huawei.openstack4j.openstack.ecs.v1.contants.InterruptionPolicyEnum; import com.huawei.openstack4j.openstack.ecs.v1.contants.ServerChargingMode; @JsonRootName("server") @@ -68,6 +69,34 @@ public class ServerExtendParam { @JsonProperty("spotPrice") String spotPrice; + /** + * 购买的竞价实例时长。 + * 约束: + * 仅interruption_policy=immediate 时该字段有效 。 + * spot_duration_hours大于0。最大值由预测系统给出可以从flavor的extra_specs的cond:spot_block:operation:longest_duration_hours字段中查询。 + */ + @JsonProperty("spot_duration_hours") + Integer spotDurationHours; + + /** + * 表示购买的“竞价实例时长”的个数 + * 约束: + * 仅spot_duration_hours>0 时该字段有效。 + * spot_duration_hours小于6时,spot_duration_count值必须为1。 + * spot_duration_hours等于6时,spot_duration_count大于等于1。 + * spot_duration_count的最大值由预测系统给出可以从flavor的extra_specs的cond:spot_block:operation:longest_duration_count字段中查询。 + */ + @JsonProperty("spot_duration_count") + Integer spotDurationCount; + + /** + * 竞价实例中断策略,当前支持immediate。 + * 约束: + * 当interruption_policy=immediate时表示释放策略为立即释放。 + */ + @JsonProperty("interruption_policy") + InterruptionPolicyEnum interruptionPolicy; + @java.beans.ConstructorProperties({ "chargingMode", "regionId", "autoRecovery", "enterpriseProjectId"}) public ServerExtendParam(ServerChargingMode chargingMode, String regionId, Boolean autoRecovery, String enterpriseProjectId) { this.chargingMode = chargingMode; @@ -86,6 +115,20 @@ public ServerExtendParam(ServerChargingMode chargingMode, String regionId, Boole this.spotPrice = spotPrice; } + @java.beans.ConstructorProperties({"chargingMode", "regionId", "autoRecovery", "enterpriseProjectId", "marketType", "spotPrice", "spotDurationHours", "spotDurationCount", "interruptionPolicy"}) + public ServerExtendParam(ServerChargingMode chargingMode, String regionId, Boolean autoRecovery, String enterpriseProjectId, + String marketType, String spotPrice, Integer spotDurationHours, Integer spotDurationCount, InterruptionPolicyEnum interruptionPolicy) { + this.chargingMode = chargingMode; + this.regionId = regionId; + this.autoRecovery = autoRecovery; + this.enterpriseProjectId = enterpriseProjectId; + this.marketType = marketType; + this.spotPrice = spotPrice; + this.spotDurationHours = spotDurationHours; + this.spotDurationCount = spotDurationCount; + this.interruptionPolicy = interruptionPolicy; + } + public ServerExtendParam() { } @@ -117,12 +160,42 @@ public String getSpotPrice() { return spotPrice; } - @Override - public String toString() { - return "ServerExtendParam(chargingMode=" + this.getChargingMode() + ", regionId=" + this.getRegionId() - + ", autoRecovery=" + this.getAutoRecovery() + ", enterpriseProjectId=" + this.getEnterpriseProjectId() - + ", marketType=" + this.getMarketType() + ", spotPrice=" + this.getSpotPrice() + ")"; - } + public Integer getSpotDurationHours() { + return spotDurationHours; + } + + public Integer getSpotDurationCount() { + return spotDurationCount; + } + + public InterruptionPolicyEnum getInterruptionPolicy() { + return interruptionPolicy; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ServerExtendParam(chargingMode="); + builder.append(this.getChargingMode()); + builder.append(", regionId="); + builder.append(this.getRegionId()); + builder.append(", autoRecovery="); + builder.append(this.getAutoRecovery()); + builder.append(", enterpriseProjectId="); + builder.append(this.getEnterpriseProjectId()); + builder.append(", marketType="); + builder.append(this.getMarketType()); + builder.append(", spotPrice="); + builder.append(this.getSpotPrice()); + builder.append(", spotDurationHours="); + builder.append(this.getSpotDurationHours()); + builder.append(", spotDurationCount="); + builder.append(this.getSpotDurationCount()); + builder.append(", interruptionPolicy="); + builder.append(this.getInterruptionPolicy()); + builder.append(")"); + return builder.toString(); + } public ServerExtendParamBuilder toBuilder() { return new ServerExtendParamBuilder().chargingMode(this.chargingMode).regionId(this.regionId) @@ -136,6 +209,10 @@ public static class ServerExtendParamBuilder { private String enterpriseProjectId; private String marketType; private String spotPrice; + Integer spotDurationHours; + Integer spotDurationCount; + InterruptionPolicyEnum interruptionPolicy; + ServerExtendParamBuilder() { } @@ -169,9 +246,25 @@ public ServerExtendParam.ServerExtendParamBuilder spotPrice(String spotPrice) { return this; } + public ServerExtendParam.ServerExtendParamBuilder spotDurationHours(Integer spotDurationHours) { + this.spotDurationHours = spotDurationHours; + return this; + } + + public ServerExtendParam.ServerExtendParamBuilder spotDurationCount(Integer spotDurationCount) { + this.spotDurationCount = spotDurationCount; + return this; + } + + public ServerExtendParam.ServerExtendParamBuilder interruptionPolicy(InterruptionPolicyEnum interruptionPolicy) { + this.interruptionPolicy = interruptionPolicy; + return this; + } + public ServerExtendParam build() { if (null != marketType) { - return new ServerExtendParam(chargingMode, regionId, autoRecovery, enterpriseProjectId, marketType, spotPrice); + return new ServerExtendParam(chargingMode, regionId, autoRecovery, enterpriseProjectId, + marketType, spotPrice, spotDurationHours, spotDurationCount, interruptionPolicy); } else { return new ServerExtendParam(chargingMode, regionId, autoRecovery, enterpriseProjectId); } @@ -180,9 +273,27 @@ public ServerExtendParam build() { @Override public String toString() { - return "ServerExtendParam.ServerExtendParamBuilder(chargingMode=" + this.chargingMode + ", regionId=" - + this.regionId + ", autoRecovery=" + this.autoRecovery + ", enterpriseProjectId=" + this.enterpriseProjectId - + ", marketType=" + this.marketType + ", spotPrice=" + this.spotPrice + ")"; + StringBuilder builder = new StringBuilder(); + builder.append("ServerExtendParam.ServerExtendParamBuilder(chargingMode="); + builder.append(this.chargingMode); + builder.append(", regionId="); + builder.append(this.regionId); + builder.append(", autoRecovery="); + builder.append(this.autoRecovery); + builder.append(", enterpriseProjectId="); + builder.append(this.enterpriseProjectId); + builder.append(", marketType="); + builder.append(this.marketType); + builder.append(", spotPrice="); + builder.append(this.spotPrice); + builder.append(", spotDurationHours="); + builder.append(this.spotDurationHours); + builder.append(", spotDurationCount="); + builder.append(this.spotDurationCount); + builder.append(", interruptionPolicy="); + builder.append(this.interruptionPolicy); + builder.append(")"); + return builder.toString(); } } } diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/contants/InterruptionPolicyEnum.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/contants/InterruptionPolicyEnum.java new file mode 100644 index 0000000..dadcb88 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/contants/InterruptionPolicyEnum.java @@ -0,0 +1,13 @@ +package com.huawei.openstack4j.openstack.ecs.v1_1.contants; + +public enum InterruptionPolicyEnum { + /** + * Enum IMMEDIATE for value: "immediate" + */ + immediate, + /** + * Enum DELAY for value: "delay" + */ + delay + +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerExtendParam.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerExtendParam.java index aa5a90c..a7c3f87 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerExtendParam.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerExtendParam.java @@ -15,6 +15,7 @@ *******************************************************************************/ package com.huawei.openstack4j.openstack.ecs.v1_1.domain; +import com.huawei.openstack4j.openstack.ecs.v1_1.contants.InterruptionPolicyEnum; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -113,4 +114,32 @@ public class ServerExtendParam { */ @JsonProperty("spotPrice") String spotPrice; + + /** + * 购买的竞价实例时长。 + * 约束: + * 仅interruption_policy=immediate 时该字段有效 。 + * spot_duration_hours大于0。最大值由预测系统给出可以从flavor的extra_specs的cond:spot_block:operation:longest_duration_hours字段中查询。 + */ + @JsonProperty("spot_duration_hours") + Integer spotDurationHours; + + /** + * 表示购买的“竞价实例时长”的个数 + * 约束: + * 仅spot_duration_hours>0 时该字段有效。 + * spot_duration_hours小于6时,spot_duration_count值必须为1。 + * spot_duration_hours等于6时,spot_duration_count大于等于1。 + * spot_duration_count的最大值由预测系统给出可以从flavor的extra_specs的cond:spot_block:operation:longest_duration_count字段中查询。 + */ + @JsonProperty("spot_duration_count") + Integer spotDurationCount; + + /** + * 竞价实例中断策略,当前支持immediate。 + * 约束: + * 当interruption_policy=immediate时表示释放策略为立即释放。 + */ + @JsonProperty("interruption_policy") + InterruptionPolicyEnum interruptionPolicy; } diff --git a/distribution/pom.xml b/distribution/pom.xml index 63b8c8b..de42ff6 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -20,7 +20,7 @@ com.huawei openstack4j-parent - 1.0.23 + 1.0.24 4.0.0 openstack4j diff --git a/pom.xml b/pom.xml index bb647fe..56b8eb3 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 4.0.0 com.huawei openstack4j-parent - 1.0.23 + 1.0.24 OpenStack4j Parent OpenStack Java API http://github.com/ContainX/openstack4j/ From eb472a6005264e62d7c122b4776f0e80214ec5bf Mon Sep 17 00:00:00 2001 From: wuchen Date: Mon, 31 Aug 2020 22:28:20 +0800 Subject: [PATCH 2/3] release 1.0.25 code --- codedex_java.sh | 50 ------------------ connectors/http-connector/pom.xml | 2 +- connectors/httpclient/pom.xml | 2 +- connectors/jersey2/pom.xml | 2 +- connectors/okhttp/pom.xml | 2 +- connectors/pom.xml | 2 +- connectors/resteasy/pom.xml | 2 +- core-functional-test/pom.xml | 2 +- core-integration-test/pom.xml | 2 +- core-sample/pom.xml | 2 +- core-test/pom.xml | 2 +- .../openstack4j/api/storage/VolumeTests.java | 2 +- .../src/main/resources/storage/v2/volume.json | 1 + core/pom.xml | 2 +- .../api/compute/ServerService.java | 12 +++++ .../model/storage/block/Volume.java | 2 +- .../compute/domain/NovaRemoteConsole.java | 24 +++++++++ .../domain/NovaRemoteConsoleResponse.java | 31 +++++++++++ .../compute/internal/ServerServiceImpl.java | 29 +++++++---- .../ecs/v1/domain/RemoteConsole.java | 24 +++++++++ .../ecs/v1/domain/RemoteConsoleResponse.java | 28 ++++++++++ .../ecs/v1/domain/ServerCreateRequest.java | 19 +++++++ .../ecs/v1/internal/CloudServerService.java | 49 +++++++++++++---- .../ecs/v1_1/domain/ServerCreateRequest.java | 19 +++++++ .../ecs/v1_1/internal/CloudServerService.java | 34 ++++++++++-- distribution/pom.xml | 2 +- examples/compute/v2/RemoteConsoleDemo.java | 46 ++++++++++++++++ examples/ecs/CloudServer.java | 52 ++++++++++++++++++- examples/ecs/FlavorDemo.java | 2 +- examples/ecs/ServerDemo.java | 3 +- examples/ecs/v1/CloudServerTagService.java | 8 +-- examples/ecs/v1/CloudServerV1.java | 6 ++- examples/ecs/v1/RemoteConsoleDemo.java | 41 +++++++++++++++ examples/ecs/v1_1/CloudServer.java | 25 ++++++++- pom.xml | 2 +- 35 files changed, 432 insertions(+), 101 deletions(-) delete mode 100644 codedex_java.sh create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsole.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsoleResponse.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsole.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsoleResponse.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerCreateRequest.java create mode 100644 core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerCreateRequest.java create mode 100644 examples/compute/v2/RemoteConsoleDemo.java create mode 100644 examples/ecs/v1/RemoteConsoleDemo.java diff --git a/codedex_java.sh b/codedex_java.sh deleted file mode 100644 index 60e9bb5..0000000 --- a/codedex_java.sh +++ /dev/null @@ -1,50 +0,0 @@ - #!/bin/sh - export JAVA_HOME=/root/buildbox/jdk1.8.0_151 - export MAVN_HOME=/root/buildbox/apache-maven-3.3.3 - - export CODEDEX_PATH=/root/buildbox/CodeDEX_V3 - export FORTIFY_HOME=$CODEDEX_PATH/tool/tools/fortify_17.20 - export COVERITY_HOME=$CODEDEX_PATH/tool/tools/coverity_2018.01 - export ZA_HOME=$CODEDEX_PATH/tool/7za/Linux - export COMPILER_EXTRACT=$CODEDEX_PATH/compiler-extract - export CODEMARS_HOME=$CODEDEX_PATH/tool/tools/codemars_Newest - - #path - export PATH=$JAVA_HOME/bin:$MAVN_HOME/bin:$FORTIFY_HOME/bin:$COVERITY_HOME/bin:$COMPILER_EXTRACT/bin:$CODEMARS_HOME/bin:$PATH - - # FORTIFY_BUILD_ID可设置自己服务的ID值,这个ID名由数字、字母、下划线组成,不支持包含中划线- - export FORTIFY_BUILD_ID=fuxi_codedex_test1 - export language=java - - #使用环境变量INTER_DIR(中间文件目录)、SRC_WS(源码路径)、SCAN_DIR(待扫描的代码相对路径) - export inter_dir=$INTER_DIR - export codemars_tmp_dir=$inter_dir/codemars_tmp - export cov_tmp_dir=$inter_dir/cov_tmp - export for_tmp_dir=$inter_dir/for_tmp - export project_root=$SRC_WS/$SCAN_DIR - - rm -rf $inter_dir - - cd $CODEMARS_HOME - sh CodeMars.sh -j -source $project_root -output $codemars_tmp_dir/CodeMars.json - - cd $project_root - cov-build --dir "$cov_tmp_dir" mvn -f sdk-java-master/pom.xml clean install -Dmaven.test.skip=true - - cd $CODEDEX_PATH/compiler-extract/bin - compiler-extract -fh $FORTIFY_HOME -lang $language -dir $inter_dir -b $FORTIFY_BUILD_ID - - cd $inter_dir - sourceanalyzer -b $FORTIFY_BUILD_ID -Dcom.fortify.sca.ProjectRoot=$for_tmp_dir -export-build-session $FORTIFY_BUILD_ID.mbs - - cd $cov_tmp_dir - $ZA_HOME/7za a -tzip coverity.zip * -r - mv coverity.zip "$inter_dir" - - cd $inter_dir - $ZA_HOME/7za a -tzip fortify.zip $FORTIFY_BUILD_ID.mbs - mv fortify.zip "$inter_dir" - - cd $codemars_tmp_dir - zip codemars.zip CodeMars.json - cp codemars.zip $inter_dir/ \ No newline at end of file diff --git a/connectors/http-connector/pom.xml b/connectors/http-connector/pom.xml index 2cea86c..41214a3 100644 --- a/connectors/http-connector/pom.xml +++ b/connectors/http-connector/pom.xml @@ -20,7 +20,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.24 + 1.0.25 OpenStack4j HttpURL Connector openstack4j-http-connector diff --git a/connectors/httpclient/pom.xml b/connectors/httpclient/pom.xml index 00323c4..23836ef 100644 --- a/connectors/httpclient/pom.xml +++ b/connectors/httpclient/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.24 + 1.0.25 4.0.0 openstack4j-httpclient diff --git a/connectors/jersey2/pom.xml b/connectors/jersey2/pom.xml index 0c1dd76..ff5c7b0 100644 --- a/connectors/jersey2/pom.xml +++ b/connectors/jersey2/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.24 + 1.0.25 4.0.0 openstack4j-jersey2 diff --git a/connectors/okhttp/pom.xml b/connectors/okhttp/pom.xml index e8e34c5..b92a2fa 100644 --- a/connectors/okhttp/pom.xml +++ b/connectors/okhttp/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.24 + 1.0.25 4.0.0 openstack4j-okhttp diff --git a/connectors/pom.xml b/connectors/pom.xml index a348433..b015dbc 100644 --- a/connectors/pom.xml +++ b/connectors/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 4.0.0 com.huawei.openstack4j.connectors diff --git a/connectors/resteasy/pom.xml b/connectors/resteasy/pom.xml index 1110969..85eec0c 100644 --- a/connectors/resteasy/pom.xml +++ b/connectors/resteasy/pom.xml @@ -19,7 +19,7 @@ com.huawei.openstack4j.connectors openstack4j-connectors - 1.0.24 + 1.0.25 4.0.0 openstack4j-resteasy diff --git a/core-functional-test/pom.xml b/core-functional-test/pom.xml index 13aa7b0..f0e11ab 100644 --- a/core-functional-test/pom.xml +++ b/core-functional-test/pom.xml @@ -4,7 +4,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 openstack4j-core-functional-test OpenStack4j Core Functional Test Cases diff --git a/core-integration-test/pom.xml b/core-integration-test/pom.xml index a13ad80..d404b07 100644 --- a/core-integration-test/pom.xml +++ b/core-integration-test/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 4.0.0 openstack4j-core-integration-test diff --git a/core-sample/pom.xml b/core-sample/pom.xml index cf33824..cbd8b1f 100644 --- a/core-sample/pom.xml +++ b/core-sample/pom.xml @@ -4,7 +4,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 openstack-core-sample OpenStack4j Sample diff --git a/core-test/pom.xml b/core-test/pom.xml index b71f604..3353118 100644 --- a/core-test/pom.xml +++ b/core-test/pom.xml @@ -19,7 +19,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 4.0.0 openstack4j-core-test diff --git a/core-test/src/main/java/com/huawei/openstack4j/api/storage/VolumeTests.java b/core-test/src/main/java/com/huawei/openstack4j/api/storage/VolumeTests.java index 77635ff..e37b780 100644 --- a/core-test/src/main/java/com/huawei/openstack4j/api/storage/VolumeTests.java +++ b/core-test/src/main/java/com/huawei/openstack4j/api/storage/VolumeTests.java @@ -110,7 +110,7 @@ public void getVolumeV1() throws Exception { public void getVolumeV2() throws Exception { // Check get volume respondWith("/storage/v2/volume.json"); - Volume volume = osv3().blockStorage().volumes().get("8a9287b7-4f4d-4213-8d75-63470f19f27c"); + Volume volume = osv3().blockStorage().volumes().get("de3108dd-860c-43bc-a572-42a47f561582"); RecordedRequest getRequest = server.takeRequest(); assertTrue(getRequest.getPath().matches("/v[12]/project-id/volumes/8a9287b7-4f4d-4213-8d75-63470f19f27c")); diff --git a/core-test/src/main/resources/storage/v2/volume.json b/core-test/src/main/resources/storage/v2/volume.json index 86d1480..e867d0d 100644 --- a/core-test/src/main/resources/storage/v2/volume.json +++ b/core-test/src/main/resources/storage/v2/volume.json @@ -27,6 +27,7 @@ "name": "test-volume", "replication_status": "disabled", "consistencygroup_id": null, + "os-vol-mig-status-attr:migstat": "error", "source_volid": "11111111-1111-1111-1111-111111111111", "snapshot_id": "22222222-2222-2222-2222-222222222222", "os-volume-replication:extended_status": null, diff --git a/core/pom.xml b/core/pom.xml index 919e2ef..4368695 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -20,7 +20,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 4.0.0 openstack4j-core diff --git a/core/src/main/java/com/huawei/openstack4j/api/compute/ServerService.java b/core/src/main/java/com/huawei/openstack4j/api/compute/ServerService.java index 51e8124..da047e7 100644 --- a/core/src/main/java/com/huawei/openstack4j/api/compute/ServerService.java +++ b/core/src/main/java/com/huawei/openstack4j/api/compute/ServerService.java @@ -54,6 +54,8 @@ import com.huawei.openstack4j.model.compute.actions.LiveMigrateOptions; import com.huawei.openstack4j.model.compute.actions.RebuildOptions; import com.huawei.openstack4j.model.compute.builder.ServerCreateBuilder; +import com.huawei.openstack4j.openstack.compute.domain.NovaRemoteConsole; +import com.huawei.openstack4j.openstack.compute.domain.NovaRemoteConsoleResponse; /** * Server Operations API @@ -259,6 +261,16 @@ public interface ServerService { */ String getConsoleOutput(String serverId, int numLines); + /** + * This API is used to obtain the address for remotely logging in to an ECS using VNC. + * + * @param serverId Specifies the ECS ID. + * @param remoteConsole Obtains the address for remotely logging in to an ECS using VNC. + * @param headers Request header + * @return Obtains the address for remotely logging in to an ECS + */ + NovaRemoteConsoleResponse getRemoteConsole(String serverId, NovaRemoteConsole remoteConsole, Map headers); + /** * Obtains the VNC Console connection information for the given server and VNC Console Type * diff --git a/core/src/main/java/com/huawei/openstack4j/model/storage/block/Volume.java b/core/src/main/java/com/huawei/openstack4j/model/storage/block/Volume.java index 985c90b..07a1d88 100644 --- a/core/src/main/java/com/huawei/openstack4j/model/storage/block/Volume.java +++ b/core/src/main/java/com/huawei/openstack4j/model/storage/block/Volume.java @@ -81,7 +81,7 @@ public static Status fromValue(String status) { } public enum MigrationStatus { - NONE, MIGRATING + NONE, MIGRATING, SUCCESS, STARTING, DELETING, ERROR ; @JsonValue diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsole.java b/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsole.java new file mode 100644 index 0000000..b146932 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsole.java @@ -0,0 +1,24 @@ +package com.huawei.openstack4j.openstack.compute.domain; + +import com.fasterxml.jackson.annotation.JsonRootName; +import com.huawei.openstack4j.model.ModelEntity; +import lombok.*; + +@Getter +@ToString +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonRootName("remote_console") +public class NovaRemoteConsole implements ModelEntity { + + /** + * 远程登录的类型,请将type配置为“novnc”。 + */ + private String type; + + /** + * 远程登录协议,请将protocol配置为“vnc”。 + */ + private String protocol; +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsoleResponse.java b/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsoleResponse.java new file mode 100644 index 0000000..6bb0748 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/compute/domain/NovaRemoteConsoleResponse.java @@ -0,0 +1,31 @@ +package com.huawei.openstack4j.openstack.compute.domain; + +import com.fasterxml.jackson.annotation.JsonRootName; +import com.huawei.openstack4j.model.ModelEntity; +import lombok.*; + +@Getter +@ToString +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonRootName("remote_console") +public class NovaRemoteConsoleResponse implements ModelEntity { + + /** + * 远程登录的类型 + */ + private String type; + + /** + * 远程登录协议 + */ + private String protocol; + + /** + * 远程登录的url。 + * + * 该url有效时间10min,超过10min请重新获取。 + */ + private String url; +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/compute/internal/ServerServiceImpl.java b/core/src/main/java/com/huawei/openstack4j/openstack/compute/internal/ServerServiceImpl.java index 8e37e62..685f6a2 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/compute/internal/ServerServiceImpl.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/compute/internal/ServerServiceImpl.java @@ -38,6 +38,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import com.huawei.openstack4j.openstack.compute.domain.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,20 +67,9 @@ import com.huawei.openstack4j.model.compute.actions.RebuildOptions; import com.huawei.openstack4j.model.compute.builder.ServerCreateBuilder; import com.huawei.openstack4j.openstack.common.Metadata; -import com.huawei.openstack4j.openstack.compute.domain.AdminPass; -import com.huawei.openstack4j.openstack.compute.domain.ConsoleOutput; -import com.huawei.openstack4j.openstack.compute.domain.ConsoleOutputOptions; -import com.huawei.openstack4j.openstack.compute.domain.MetadataItem; -import com.huawei.openstack4j.openstack.compute.domain.NovaPassword; -import com.huawei.openstack4j.openstack.compute.domain.NovaServer; import com.huawei.openstack4j.openstack.compute.domain.NovaServer.Servers; -import com.huawei.openstack4j.openstack.compute.domain.NovaServerCreate; -import com.huawei.openstack4j.openstack.compute.domain.NovaServerUpdate; -import com.huawei.openstack4j.openstack.compute.domain.NovaVNCConsole; -import com.huawei.openstack4j.openstack.compute.domain.NovaVolumeAttachment; import com.huawei.openstack4j.openstack.compute.domain.actions.BackupAction; import com.huawei.openstack4j.openstack.compute.domain.actions.BasicActions; -import com.huawei.openstack4j.openstack.compute.domain.actions.BasicActions.ChangePassword; import com.huawei.openstack4j.openstack.compute.domain.actions.BasicActions.ConfirmResize; import com.huawei.openstack4j.openstack.compute.domain.actions.BasicActions.Migrate; import com.huawei.openstack4j.openstack.compute.domain.actions.BasicActions.Reboot; @@ -364,6 +354,23 @@ public String getConsoleOutput(String serverId, int numLines) { return (c != null) ? c.getOutput() : null; } + /** + * {@inheritDoc} + */ + @Override + public NovaRemoteConsoleResponse getRemoteConsole(String serverId, NovaRemoteConsole remoteConsole, Map headers) { + checkNotNull(serverId); + checkNotNull(remoteConsole); + checkNotNull(remoteConsole.getProtocol()); + checkNotNull(remoteConsole.getType()); + checkNotNull(headers); + + return post(NovaRemoteConsoleResponse.class, uri("/servers/%s/remote-consoles", serverId)) + .entity(remoteConsole).headers(headers) + .execute(); + } + + /** * {@inheritDoc} */ diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsole.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsole.java new file mode 100644 index 0000000..74fa638 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsole.java @@ -0,0 +1,24 @@ +package com.huawei.openstack4j.openstack.ecs.v1.domain; + +import com.fasterxml.jackson.annotation.JsonRootName; +import com.huawei.openstack4j.model.ModelEntity; +import lombok.*; + +@Getter +@ToString +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonRootName("remote_console") +public class RemoteConsole implements ModelEntity { + + /** + * 远程登录的类型,请将type配置为“novnc”。 + */ + private String type; + + /** + * 远程登录协议,请将protocol配置为“vnc”。 + */ + private String protocol; +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsoleResponse.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsoleResponse.java new file mode 100644 index 0000000..0df82e7 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/RemoteConsoleResponse.java @@ -0,0 +1,28 @@ +package com.huawei.openstack4j.openstack.ecs.v1.domain; + +import com.fasterxml.jackson.annotation.JsonRootName; +import com.huawei.openstack4j.model.ModelEntity; +import lombok.*; + +@Getter +@ToString +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonRootName("remote_console") +public class RemoteConsoleResponse implements ModelEntity { + + /** + * 远程登录的类型 + */ + private String type; + + /** + * 远程登录协议 + */ + private String protocol; + /** + * 远程登录的url + */ + private String url; +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerCreateRequest.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerCreateRequest.java new file mode 100644 index 0000000..9d48d51 --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/domain/ServerCreateRequest.java @@ -0,0 +1,19 @@ +package com.huawei.openstack4j.openstack.ecs.v1.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.huawei.openstack4j.model.ModelEntity; + +public class ServerCreateRequest implements ModelEntity { + + private static final long serialVersionUID = -2887662917095175105L; + + @JsonProperty("dry_run") + private Boolean isDryRun; + @JsonProperty("server") + private ServerCreate server; + + public ServerCreateRequest(Boolean isDryRun, ServerCreate servers1) { + this.isDryRun = isDryRun; + this.server = servers1; + } +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/internal/CloudServerService.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/internal/CloudServerService.java index 2435de4..1cfc18c 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/internal/CloudServerService.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1/internal/CloudServerService.java @@ -30,16 +30,9 @@ import com.huawei.openstack4j.model.compute.StopType; import com.huawei.openstack4j.openstack.common.AsyncJobEntity; import com.huawei.openstack4j.openstack.common.IdResourceEntity; - import com.huawei.openstack4j.openstack.ecs.v1.domain.CloudAbsoluteLimit; - import com.huawei.openstack4j.openstack.ecs.v1.domain.CloudServer; - import com.huawei.openstack4j.openstack.ecs.v1.domain.AsyncServerRespEntity; + import com.huawei.openstack4j.openstack.ecs.v1.domain.*; import com.huawei.openstack4j.openstack.ecs.v1.domain.CloudServer.CloudServers; - import com.huawei.openstack4j.openstack.ecs.v1.domain.Flavor; import com.huawei.openstack4j.openstack.ecs.v1.domain.Flavor.Flavors; - import com.huawei.openstack4j.openstack.ecs.v1.domain.ResizeServer; - import com.huawei.openstack4j.openstack.ecs.v1.domain.ServerCreate; - import com.huawei.openstack4j.openstack.ecs.v1.domain.SupportAutoRecovery; - import com.huawei.openstack4j.openstack.ecs.v1.domain.ResetPassword; public class CloudServerService extends BaseElasticComputeServices { @@ -54,7 +47,6 @@ public String create(ServerCreate creation) { checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()), "parameter `flavorRef` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getName()), "parameter `name` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getVpcId()), "parameter `vpcid` should not be empty"); - checkArgument(!Strings.isNullOrEmpty(creation.getAvailabilityZone()), "parameter `availability_zone` should not be empty"); checkArgument(!(creation.getPersonality() != null && creation.getPersonality().size() > 5), "size of parameter `personality` should not greate than 5"); checkArgument(creation.getNetworks() != null && creation.getNetworks().size() > 0, @@ -70,14 +62,38 @@ public String create(ServerCreate creation) { * @return entity of the asynchronous create server task */ public AsyncServerRespEntity createServer(ServerCreate creation) { + checkArgument(!Strings.isNullOrEmpty(creation.getImageRef()), "parameter `imageRef` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()), "parameter `flavorRef` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getName()), "parameter `name` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getVpcId()), "parameter `vpcid` should not be empty"); + checkArgument(creation.getNetworks() != null && creation.getNetworks().size() > 0, + "parameter `networks` should not be empty"); + checkArgument(creation.getRootVolume() != null, "parameter `root_volume` should not be empty"); + return post(AsyncServerRespEntity.class, "/cloudservers").entity(creation).execute(); + } + + /** + * create one or multiple server + * + * @param creation + * @return job-id of the asynchronous create server task + */ + public AsyncServerRespEntity createServer(ServerCreate creation, Boolean isDryRun) { checkArgument(!Strings.isNullOrEmpty(creation.getImageRef()), "parameter `imageRef` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()), "parameter `flavorRef` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getName()), "parameter `name` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getVpcId()), "parameter `vpcid` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getAvailabilityZone()), "parameter `availability_zone` should not be empty"); + checkArgument(!(creation.getPersonality() != null && creation.getPersonality().size() > 5), + "size of parameter `personality` should not greate than 5"); checkArgument(creation.getNetworks() != null && creation.getNetworks().size() > 0, "parameter `networks` should not be empty"); checkArgument(creation.getRootVolume() != null, "parameter `root_volume` should not be empty"); + ServerCreateRequest serverCreateRequest = new ServerCreateRequest(isDryRun, creation); + if (isDryRun) { + post(AsyncServerRespEntity.class, "/cloudservers").entity(serverCreateRequest).execute(); + return null; + } return post(AsyncServerRespEntity.class, "/cloudservers").entity(creation).execute(); } @@ -256,6 +272,21 @@ public ActionResponse resetPassword(String serverId, ResetPassword resetPassword return put(ActionResponse.class, uri("/cloudservers/" + serverId + "/os-reset-password")).entity(resetPassword).execute(); } + /** + * Obtaining the VNC Login Address + * + * @param serverId + * @return + */ + public RemoteConsoleResponse remoteConsole(String serverId, RemoteConsole remoteConsole) { + checkArgument(!Strings.isNullOrEmpty(serverId), "parameter `serverId` should not be empty"); + checkArgument(!(remoteConsole == null), "parameter `remote_console` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(remoteConsole.getType()), "parameter `type` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(remoteConsole.getProtocol()), "parameter `protocol` should not be empty"); + return post(RemoteConsoleResponse.class, uri("/cloudservers/" + serverId + "/remote_console")).entity(remoteConsole).execute(); + } + + // /** // *Query cloud server specification change support list // * @return diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerCreateRequest.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerCreateRequest.java new file mode 100644 index 0000000..94329fe --- /dev/null +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/domain/ServerCreateRequest.java @@ -0,0 +1,19 @@ +package com.huawei.openstack4j.openstack.ecs.v1_1.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.huawei.openstack4j.model.ModelEntity; + +public class ServerCreateRequest implements ModelEntity { + + private static final long serialVersionUID = -6252374090930619106L; + @JsonProperty("dry_run") + private Boolean isDryRun; + + @JsonProperty("server") + private ServerCreate server; + + public ServerCreateRequest(Boolean isDryRun, ServerCreate server) { + this.isDryRun = isDryRun; + this.server = server; + } +} diff --git a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/internal/CloudServerService.java b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/internal/CloudServerService.java index 96dd0a7..ffaa041 100644 --- a/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/internal/CloudServerService.java +++ b/core/src/main/java/com/huawei/openstack4j/openstack/ecs/v1_1/internal/CloudServerService.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2018 Huawei Technologies Co.,Ltd. - * + * * Licensed 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 @@ -22,16 +22,36 @@ import com.huawei.openstack4j.openstack.ecs.v1_1.domain.AsyncServerRespEntity; import com.huawei.openstack4j.openstack.ecs.v1_1.domain.ResizeServer; import com.huawei.openstack4j.openstack.ecs.v1_1.domain.ServerCreate; +import com.huawei.openstack4j.openstack.ecs.v1_1.domain.ServerCreateRequest; public class CloudServerService extends BaseElasticComputeServices { /** * create one or multiple server - * + * * @param creation * @return job-id of the asynchronous create server task */ public AsyncServerRespEntity create(ServerCreate creation) { + checkArgument(!Strings.isNullOrEmpty(creation.getImageRef()), "parameter `imageRef` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()), "parameter `flavorRef` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getName()), "parameter `name` should not be empty"); + checkArgument(!Strings.isNullOrEmpty(creation.getVpcId()), "parameter `vpcid` should not be empty"); + checkArgument(!(creation.getPersonality() != null && creation.getPersonality().size() > 5), + "size of parameter `personality` should not greate than 5"); + checkArgument(creation.getNetworks() != null && creation.getNetworks().size() > 0, + "parameter `networks` should not be empty"); + checkArgument(creation.getRootVolume() != null, "parameter `root_volume` should not be empty"); + return post(AsyncServerRespEntity.class, "/cloudservers").entity(creation).execute(); + } + + /** + * create one or multiple server + * + * @param creation + * @return job-id of the asynchronous create server task + */ + public AsyncServerRespEntity create(ServerCreate creation, Boolean isDryRun) { checkArgument(!Strings.isNullOrEmpty(creation.getImageRef()), "parameter `imageRef` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getFlavorRef()), "parameter `flavorRef` should not be empty"); checkArgument(!Strings.isNullOrEmpty(creation.getName()), "parameter `name` should not be empty"); @@ -42,6 +62,12 @@ public AsyncServerRespEntity create(ServerCreate creation) { checkArgument(creation.getNetworks() != null && creation.getNetworks().size() > 0, "parameter `networks` should not be empty"); checkArgument(creation.getRootVolume() != null, "parameter `root_volume` should not be empty"); + + ServerCreateRequest serverCreateRequest = new ServerCreateRequest(isDryRun, creation); + if (isDryRun) { + post(AsyncServerRespEntity.class, "/cloudservers").entity(serverCreateRequest).execute(); + return null; + } return post(AsyncServerRespEntity.class, "/cloudservers").entity(creation).execute(); } diff --git a/distribution/pom.xml b/distribution/pom.xml index de42ff6..2cf8c7c 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -20,7 +20,7 @@ com.huawei openstack4j-parent - 1.0.24 + 1.0.25 4.0.0 openstack4j diff --git a/examples/compute/v2/RemoteConsoleDemo.java b/examples/compute/v2/RemoteConsoleDemo.java new file mode 100644 index 0000000..23fa076 --- /dev/null +++ b/examples/compute/v2/RemoteConsoleDemo.java @@ -0,0 +1,46 @@ +package com.huawei.openstack.sample.ecs.v1; + +import com.huawei.openstack4j.api.OSClient; +import com.huawei.openstack4j.core.transport.Config; +import com.huawei.openstack4j.model.common.Identifier; +import com.huawei.openstack4j.openstack.OSFactory; +import com.huawei.openstack4j.openstack.compute.domain.NovaRemoteConsole; +import com.huawei.openstack4j.openstack.compute.domain.NovaRemoteConsoleResponse; + +import java.util.HashMap; +import java.util.Map; + +public class RemoteConsoleDemo { + public static void main(String[] args) { + String authUrl = "https://iam.xxxxxxx.huaweicloud.com/v3"; //endpoint Url + String username = "xxxxxxx"; //username + String password = "xxxxxxx"; //password + String projectId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //projectId + String userDomainId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //domainId + + Config config = Config.newConfig().withSSLVerificationDisabled(); + // create connection + OSClient.OSClientV3 os = OSFactory.builderV3() + .endpoint(authUrl) + .withConfig(config) + .credentials(username, password, Identifier.byId(userDomainId)) + .scopeToProject(Identifier.byId(projectId)).authenticate(); + + String serverId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; + String type = "novnc"; + String protocol = "vnc"; + + NovaRemoteConsole remoteConsole = NovaRemoteConsole.builder() + .type(type) + .protocol(protocol) + .build(); + + // "X-OpenStack-Nova-API-Version","2.6" + Map header = new HashMap<>(); + header.put("X-OpenStack-Nova-API-Version", "xxx"); + NovaRemoteConsoleResponse remoteConsoleResponse = os.compute().servers() + .getRemoteConsole(serverId, remoteConsole, header); + System.out.println(remoteConsoleResponse); + + } +} diff --git a/examples/ecs/CloudServer.java b/examples/ecs/CloudServer.java index e8553e3..1b320df 100644 --- a/examples/ecs/CloudServer.java +++ b/examples/ecs/CloudServer.java @@ -1,5 +1,7 @@ package sample; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.TimeUnit; import com.huawei.openstack4j.api.OSClient.OSClientV3; @@ -8,6 +10,8 @@ import com.huawei.openstack4j.model.compute.Server.Status; import com.huawei.openstack4j.openstack.OSFactory; import com.huawei.openstack4j.openstack.common.AsyncRespEntity; +import com.huawei.openstack4j.openstack.ecs.v1.domain.Job; +import com.huawei.openstack4j.openstack.ecs.v1.domain.SubJob; import sun.misc.BASE64Encoder; import com.huawei.openstack4j.openstack.ecs.v1.contants.IpType; @@ -82,7 +86,29 @@ public static void main(String[] args) { //create prepaid server AsyncRespEntity rep1 = os.ecsV1_1().servers().create(creation1); if (null != rep1) { - System.out.println("create server success, orderid = " + rep1.getOrderId()); + Job job = os.ecs().jobs().get(rep1.getJobId()); + while (!"SUCCESS".equals(job.getStatus()) && !"FAIL".equals(job.getStatus())) { + try { + Thread.sleep(8000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("jobStatus" + job.getStatus()); + job = os.ecs().jobs().get(rep1.getJobId()); + } + List subJobList = job.getEntities().getSubJobs(); + List successServers = new ArrayList<>(); + List failServers = new ArrayList<>(); + for (SubJob subJob : subJobList) { + if ("SUCCESS".equals(subJob.getStatus())) { + successServers.add(subJob.getEntities().getServerId()); + } else { + failServers.add(subJob.getEntities().getServerId()); + } + } + System.out.println("create server success, jobId = " + rep1.getJobId()); + System.out.println("success servers=" + successServers); + System.out.println("fail servers=" + failServers); } else { System.out.println("create server failed"); } @@ -128,7 +154,29 @@ public static void main(String[] args) { //create postpaid server AsyncRespEntity rep2 = os.ecsV1_1().servers().create(creation2); if (null != rep2) { - System.out.println("create server success, jobid = " + rep2.getJobId()); + Job job = os.ecs().jobs().get(rep2.getJobId()); + while (!"SUCCESS".equals(job.getStatus()) && !"FAIL".equals(job.getStatus())) { + try { + Thread.sleep(8000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("jobStatus" + job.getStatus()); + job = os.ecs().jobs().get(rep2.getJobId()); + } + List subJobList = job.getEntities().getSubJobs(); + List successServers = new ArrayList<>(); + List failServers = new ArrayList<>(); + for (SubJob subJob : subJobList) { + if ("SUCCESS".equals(subJob.getStatus())) { + successServers.add(subJob.getEntities().getServerId()); + } else { + failServers.add(subJob.getEntities().getServerId()); + } + } + System.out.println("create server success, jobId = " + rep2.getJobId()); + System.out.println("success servers=" + successServers); + System.out.println("fail servers=" + failServers); } else { System.out.println("create server failed"); } diff --git a/examples/ecs/FlavorDemo.java b/examples/ecs/FlavorDemo.java index ef8fa41..7210fce 100644 --- a/examples/ecs/FlavorDemo.java +++ b/examples/ecs/FlavorDemo.java @@ -22,7 +22,7 @@ public static void main(String[] args) { OSClientV3 os = OSFactory.builderV3() .endpoint(authUrl) .credentials(user, password, Identifier.byId(userDomainId)) - .scopeToProject(Identifier.byId(projectId)).authenticate() + .scopeToProject(Identifier.byId(projectId)).authenticate(); //get list of flavor List flavors = os.compute().flavors().list(); diff --git a/examples/ecs/ServerDemo.java b/examples/ecs/ServerDemo.java index 873a471..fd6e92f 100644 --- a/examples/ecs/ServerDemo.java +++ b/examples/ecs/ServerDemo.java @@ -10,6 +10,7 @@ import com.huawei.openstack4j.api.OSClient.OSClientV3; import com.huawei.openstack4j.model.common.ActionResponse; import com.huawei.openstack4j.model.common.Identifier; +import com.huawei.openstack4j.model.compute.StopType; import com.huawei.openstack4j.model.network.Network; import com.huawei.openstack4j.openstack.OSFactory; @@ -95,7 +96,7 @@ public static void main(String[] args) { } //stop server with type - ActionResponse repStopWithType = os.compute().servers().stop(serverId, StopType.HARD); + ActionResponse repStopWithType = os.compute().servers().stop(secServerId, StopType.HARD); if (repStopWithType.isSuccess()) { System.out.println("hard stop server success"); } else { diff --git a/examples/ecs/v1/CloudServerTagService.java b/examples/ecs/v1/CloudServerTagService.java index c4f03f8..dc6b38b 100644 --- a/examples/ecs/v1/CloudServerTagService.java +++ b/examples/ecs/v1/CloudServerTagService.java @@ -27,16 +27,16 @@ public static void main(String[] args) throws InterruptedException { String serverId = "server-id"; //cloud server tags add - ActionResponse actionResponse = os.ecs().tags().add(serverId,serverTags); - if (actionResponse.isSuccess()) { + ActionResponse addActionResponse = os.ecs().tags().add(serverId,serverTags); + if (addActionResponse.isSuccess()) { System.out.println("add server tags success"); } else { System.out.println("add server tags failed"); } //cloud server tags delete - ActionResponse actionResponse = os.ecs().tags().delete(serverId,serverTags); - if (actionResponse.isSuccess()) { + ActionResponse deleteActionResponse = os.ecs().tags().delete(serverId,serverTags); + if (deleteActionResponse.isSuccess()) { System.out.println("delete server tags success"); } else { System.out.println("delete server tags failed"); diff --git a/examples/ecs/v1/CloudServerV1.java b/examples/ecs/v1/CloudServerV1.java index 469e2f3..d8c4cc6 100644 --- a/examples/ecs/v1/CloudServerV1.java +++ b/examples/ecs/v1/CloudServerV1.java @@ -20,7 +20,9 @@ import com.huawei.openstack4j.openstack.ecs.v1.contants.ShareType; import com.huawei.openstack4j.openstack.ecs.v1.contants.VolumeType; import com.huawei.openstack4j.openstack.ecs.v1.domain.Bandwidth; +import com.huawei.openstack4j.openstack.ecs.v1.domain.CloudServer; import com.huawei.openstack4j.openstack.ecs.v1.domain.Job; +import com.huawei.openstack4j.openstack.ecs.v1.domain.ResetPassword; import com.huawei.openstack4j.openstack.ecs.v1.domain.SubJob; import com.huawei.openstack4j.openstack.ecs.v1.domain.CloudServer.CloudServers; import com.huawei.openstack4j.openstack.ecs.v1.domain.DataVolume; @@ -264,8 +266,8 @@ public static void main(String[] args) throws InterruptedException { //cloud server reset password ResetPassword resetPassword = ResetPassword.builder().newPassword("xxxx").build(); - ActionResponse actionResponse = os.ecs().servers().resetPassword(serverId, resetPassword); - if (actionResponse.isSuccess()) { + ActionResponse resetPwdActionResponse = os.ecs().servers().resetPassword(serverId, resetPassword); + if (resetPwdActionResponse.isSuccess()) { System.out.println("reset password success"); } else { System.out.println("reset password failed"); diff --git a/examples/ecs/v1/RemoteConsoleDemo.java b/examples/ecs/v1/RemoteConsoleDemo.java new file mode 100644 index 0000000..bcfa870 --- /dev/null +++ b/examples/ecs/v1/RemoteConsoleDemo.java @@ -0,0 +1,41 @@ +package com.huawei.openstack.sample.ecs.v1; + +import com.huawei.openstack4j.api.OSClient; +import com.huawei.openstack4j.core.transport.Config; +import com.huawei.openstack4j.model.common.Identifier; +import com.huawei.openstack4j.openstack.OSFactory; +import com.huawei.openstack4j.openstack.ecs.v1.domain.RemoteConsole; +import com.huawei.openstack4j.openstack.ecs.v1.domain.RemoteConsoleResponse; + + +public class RemoteConsoleDemo { + public static void main(String[] args) { + String authUrl = "https://iam.xxxxxxx.huaweicloud.com/v3"; //endpoint Url + String username = "xxxxxxx"; //username + String password = "xxxxxxx"; //password + String projectId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //projectId + String userDomainId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; //domainId + + Config config = Config.newConfig().withSSLVerificationDisabled(); + // create connection + OSClient.OSClientV3 os = OSFactory.builderV3() + .endpoint(authUrl) + .withConfig(config) + .credentials(username, password, Identifier.byId(userDomainId)) + .scopeToProject(Identifier.byId(projectId)).authenticate(); + + String serverId = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"; + String type = "novnc"; + String protocol = "vnc"; + + RemoteConsole remoteConsole = RemoteConsole.builder() + .type(type) + .protocol(protocol) + .build(); + + RemoteConsoleResponse remoteConsoleResponse = os.ecs().servers() + .remoteConsole(serverId, remoteConsole); + System.out.println(remoteConsoleResponse); + + } +} diff --git a/examples/ecs/v1_1/CloudServer.java b/examples/ecs/v1_1/CloudServer.java index 38bfc82..6c7463d 100644 --- a/examples/ecs/v1_1/CloudServer.java +++ b/examples/ecs/v1_1/CloudServer.java @@ -87,8 +87,29 @@ public static void main(String[] args) { //create prepaid server AsyncServerRespEntity rep1 = os.ecsV1_1().servers().create(creation1); if (null != rep1) { - System.out.println("create server success, orderid = " + rep1.getOrderId()); - System.out.println("serverIds = " + rep1.getServerIds()); + Job job = os.ecs().jobs().get(rep1.getJobId()); + while (!"SUCCESS".equals(job.getStatus()) && !"FAIL".equals(job.getStatus())) { + try { + Thread.sleep(8000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println("jobStatus" + job.getStatus()); + job = os.ecs().jobs().get(rep1.getJobId()); + } + List subJobList = job.getEntities().getSubJobs(); + List successServers = new ArrayList<>(); + List failServers = new ArrayList<>(); + for (SubJob subJob : subJobList) { + if ("SUCCESS".equals(subJob.getStatus())) { + successServers.add(subJob.getEntities().getServerId()); + } else { + failServers.add(subJob.getEntities().getServerId()); + } + } + System.out.println("create server success, jobId = " + rep1.getJobId()); + System.out.println("success servers=" + successServers); + System.out.println("fail servers=" + failServers); } else { System.out.println("create server failed"); } diff --git a/pom.xml b/pom.xml index 56b8eb3..e5ab258 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 4.0.0 com.huawei openstack4j-parent - 1.0.24 + 1.0.25 OpenStack4j Parent OpenStack Java API http://github.com/ContainX/openstack4j/ From ba9747c648ed8abbbfd0241a5062cd58710e671c Mon Sep 17 00:00:00 2001 From: wuchen <62940737+wuchen-huawei@users.noreply.github.com> Date: Sun, 6 Sep 2020 18:56:41 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 052deb2..d0f7cc5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,12 @@ +# Attention Please + +Current SDK huaweicloud-sdk-java will be deprecated and new version of SDK is recommended. Please look at https://github.com/huaweicloud/huaweicloud-sdk-java-v3 to learn more. + +# 温馨提示 + +华为云已推出新版本的 SDK 供广大用户使用,当前版本后续将不推荐使用,请移步仓库 https://github.com/huaweicloud/huaweicloud-sdk-java-v3 了解更多。 + + Java SDK The following services' SDK are included.