我是如何进行上云的

我是个大彩笔 发表于 2021/09/24 15:45:26 2021/09/24
【摘要】 这是个测试

如何进行富文本编辑测试

对象类

package com.huawei.pojo;

import
com.huaweicloud.sdk.ecs.v2.model.ServerDetail;

public class
EcsDetailResponseEntity {
private String service;
private
ServerDetail details;
private
String id;
private
String name;

public
EcsDetailResponseEntity(String service, ServerDetail details, String id, String name) {
this.service = service;
this
.details = details;
this
.id = id;
this
.name = name;
}

public EcsDetailResponseEntity() {
}

public String getService() {
return service;
}

public void setService(String service) {
this.service = service;
}

public ServerDetail getDetails() {
return details;
}

public void setDetails(ServerDetail details) {
this.details = details;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


请求类

package com.huawei.controller;



import
com.huawei.pojo.EcsDetailResponseEntity;
import
com.huaweicloud.sdk.core.auth.ICredential;
import
com.huaweicloud.sdk.core.auth.BasicCredentials;
import
com.huaweicloud.sdk.core.exception.ConnectionException;
import
com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import
com.huaweicloud.sdk.core.exception.ServiceResponseException;
import
com.huaweicloud.sdk.ecs.v2.region.EcsRegion;
import
com.huaweicloud.sdk.ecs.v2.*;
import
com.huaweicloud.sdk.ecs.v2.model.*;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
@RequestMapping(
"/ecs")
@ResponseBody
public static Object ShowServer(@RequestParam String id) {
String ak =
"FOXCKEDKTGKXGIVA5HWY";
String sk = "bx8S4L4E0KoCcGnf3pWinLEjTqjsBD3lyzhrgIC1";

ICredential auth = new BasicCredentials()
.withAk(ak)
.withSk(sk)
;

EcsClient client = EcsClient.newBuilder()
.withCredential(auth)
.withRegion(EcsRegion.valueOf(
"cn-east-3"))
.build()
;
ListServersDetailsRequest request = new ListServersDetailsRequest();

try
{
ListServersDetailsResponse response = client.listServersDetails(request)
;
System.out.println(response.toString());
EcsDetailResponseEntity ecsDetailResponseEntity = new EcsDetailResponseEntity();
response.getServers().forEach(serverDetail -> {
if(serverDetail.getId().equals(id)||serverDetail.getName().equals(id)){
ecsDetailResponseEntity.setService(
"ecs");
ecsDetailResponseEntity.setId(serverDetail.getId());
ecsDetailResponseEntity.setName(serverDetail.getName());
ecsDetailResponseEntity.setDetails(serverDetail);
}

})
;
return
ecsDetailResponseEntity;
} catch (ConnectionException e) {
e.printStackTrace()
;
} catch (RequestTimeoutException e) {
e.printStackTrace()
;
} catch (ServiceResponseException e) {
e.printStackTrace()
;
System.out.println(e.getHttpStatusCode());
System.out.println(e.getErrorCode());
System.out.println(e.getErrorMsg());
}
return new Object();
}





FROM java:8
MAINTAINER yanxin
VOLUME /tmp
ADD target/web_api-0.0.1-SNAPSHOT.jar /app.jar
EXPOSE 80
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]




修改docker.json开启2375

"hosts": ["tcp://0.0.0.0:2375","unix:///var/run/docker.sock"]


和pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.huawei</groupId>
<artifactId>web_api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>web_api</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>com.huaweicloud.sdk</groupId>
<artifactId>huaweicloud-sdk-ecs</artifactId>
<version>3.0.59</version>
</dependency>
<dependency>
<groupId>com.huawei</groupId>
<artifactId>openstack4j</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<buildArgs>
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>

</project>

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请发送邮件至:cloudbbs@huaweicloud.com;如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。