parent
44f3c76c78
commit
340598ee66
@ -0,0 +1,20 @@ |
|||||||
|
package com.gitee.sop.adminserver.api.service.param; |
||||||
|
|
||||||
|
import com.gitee.easyopen.doc.annotation.ApiDocField; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author tanghc |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
public class ServiceInstanceParam { |
||||||
|
@ApiDocField(description = "serviceId") |
||||||
|
@NotBlank(message = "serviceId不能为空") |
||||||
|
private String serviceId; |
||||||
|
|
||||||
|
@ApiDocField(description = "instanceId") |
||||||
|
@NotBlank(message = "instanceId不能为空") |
||||||
|
private String instanceId; |
||||||
|
} |
@ -1,20 +1,70 @@ |
|||||||
package com.gitee.sop.adminserver.bean; |
package com.gitee.sop.adminserver.bean; |
||||||
|
|
||||||
|
import okhttp3.MediaType; |
||||||
|
import okhttp3.Request; |
||||||
|
import okhttp3.RequestBody; |
||||||
|
import okhttp3.internal.http.HttpMethod; |
||||||
|
import org.apache.commons.lang.ArrayUtils; |
||||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||||
|
|
||||||
/** |
/** |
||||||
* https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
|
* https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
|
||||||
|
* |
||||||
* @author tanghc |
* @author tanghc |
||||||
*/ |
*/ |
||||||
public enum EurekaUri { |
public enum EurekaUri { |
||||||
|
|
||||||
/** Query for all instances */ |
/** |
||||||
QUERY_APPS("/apps"), |
* 查询所有实例 Query for all instances |
||||||
|
*/ |
||||||
|
QUERY_APPS(RequestMethod.GET, "/apps"), |
||||||
|
/** |
||||||
|
* 下线 Take instance out of service |
||||||
|
*/ |
||||||
|
OFFLINE_SERVICE(RequestMethod.PUT, "/apps/%s/%s/status?value=OUT_OF_SERVICE"), |
||||||
|
/** |
||||||
|
* 上线 Move instance back into service (remove override) |
||||||
|
*/ |
||||||
|
ONLINE_SERVICE(RequestMethod.DELETE, "/apps/%s/%s/status?value=UP"), |
||||||
; |
; |
||||||
|
public static final String URL_PREFIX = "/"; |
||||||
|
|
||||||
String uri; |
String uri; |
||||||
|
RequestMethod requestMethod; |
||||||
|
|
||||||
EurekaUri(String uri) { |
EurekaUri(RequestMethod httpMethod, String uri) { |
||||||
|
if (!uri.startsWith(URL_PREFIX)) { |
||||||
|
uri = "/" + uri; |
||||||
|
} |
||||||
this.uri = uri; |
this.uri = uri; |
||||||
|
this.requestMethod = httpMethod; |
||||||
} |
} |
||||||
|
|
||||||
public String getUri() { |
public String getUri(String... args) { |
||||||
|
if (ArrayUtils.isEmpty(args)) { |
||||||
return uri; |
return uri; |
||||||
}} |
} |
||||||
|
Object[] param = ArrayUtils.clone(args); |
||||||
|
return String.format(uri, param); |
||||||
|
} |
||||||
|
|
||||||
|
public Request getRequest(String url, String... args) { |
||||||
|
String requestUrl = url + getUri(args); |
||||||
|
Request request = this.getBuilder() |
||||||
|
.url(requestUrl) |
||||||
|
.addHeader("Content-Type", "application/json") |
||||||
|
.addHeader("Accept", "application/json") |
||||||
|
.build(); |
||||||
|
return request; |
||||||
|
} |
||||||
|
|
||||||
|
public Request.Builder getBuilder() { |
||||||
|
String method = requestMethod.name(); |
||||||
|
RequestBody requestBody = null; |
||||||
|
if (HttpMethod.requiresRequestBody(method)) { |
||||||
|
MediaType contentType = MediaType.parse(org.springframework.http.MediaType.APPLICATION_JSON_VALUE); |
||||||
|
requestBody = RequestBody.create(contentType, "{}"); |
||||||
|
} |
||||||
|
return new Request.Builder().method(requestMethod.name(), requestBody); |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue