我是如何进行上云的
如何进行富文本编辑测试
对象类
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>
- 点赞
- 收藏
- 关注作者
评论(0)