...
|
...
|
@@ -90,6 +90,15 @@ public class DockerServerDeployService { |
|
|
/**
|
|
|
* 查询回滚版本
|
|
|
*/
|
|
|
public List<String> queryImageListWithImageStore(String imageStore, String serviceName,int offset) {
|
|
|
List<String> storesWithImagePath=new ArrayList<>();
|
|
|
List<String> stores = this.queryImageList(imageStore,serviceName,offset);
|
|
|
for(String ver:stores){
|
|
|
storesWithImagePath.add("/"+imageStore+"/"+serviceName+":"+ver);
|
|
|
}
|
|
|
return storesWithImagePath;
|
|
|
}
|
|
|
|
|
|
public List<String> queryImageList(String imageStore, String serviceName,int offset) {
|
|
|
List<String> stores=new ArrayList<>();
|
|
|
JSONObject searchResult = txServer.describeImageList(imageStore,serviceName,offset );
|
...
|
...
|
@@ -181,7 +190,7 @@ public class DockerServerDeployService { |
|
|
* 检测服务的container的镜像文件是否是latest,
|
|
|
* 如果不是需要修改镜像的版本为latest
|
|
|
*/
|
|
|
public boolean checkImageLatestWithModifyFlag(String clusterId, String namespace, String serviceName,JSONArray containerJa,boolean modifyFlag){
|
|
|
public boolean checkImageLatestWithModifyFlag(String clusterId, String namespace, String serviceName,String imageStore,JSONArray containerJa,boolean modifyFlag){
|
|
|
if(containerJa==null||containerJa.size()<=0){
|
|
|
logger.info("modifyClusterServiceImageFailed: container is empty !");
|
|
|
return false;
|
...
|
...
|
@@ -194,8 +203,9 @@ public class DockerServerDeployService { |
|
|
if(StringUtils.isNotBlank(image)&&image.indexOf("/"+serviceName+":")>0){
|
|
|
int index=image.lastIndexOf(":");
|
|
|
String imageLeft=image.substring(0,index);
|
|
|
String imageLeft_to_imageStore=image.substring(0,image.lastIndexOf("/"+serviceName+":"));
|
|
|
String imageRight=image.substring(index+1);
|
|
|
if("latest".equals(imageRight)){
|
|
|
if("latest".equals(imageRight)&&imageLeft_to_imageStore.indexOf(imageStore)>0){
|
|
|
correctImageFlag=true;
|
|
|
break;
|
|
|
}else{
|
...
|
...
|
@@ -203,7 +213,13 @@ public class DockerServerDeployService { |
|
|
String containersIndexName="containers."+i+".containerName";
|
|
|
String containersIndexNameValue=jo.getString("containerName");
|
|
|
String containersIndexImage="containers."+i+".image";
|
|
|
String containersIndexImageValue=imageLeft+":latest";
|
|
|
String containersIndexImageValue;
|
|
|
if(imageLeft_to_imageStore.indexOf(imageStore)>0){
|
|
|
containersIndexImageValue=imageLeft+":latest";
|
|
|
}else{
|
|
|
containersIndexImageValue=imageLeft_to_imageStore.substring(0,imageLeft_to_imageStore.lastIndexOf("/"))+"/"+imageStore+"/"+containersIndexNameValue+":latest";
|
|
|
}
|
|
|
|
|
|
JSONObject searchResult = txServer.modifyClusterServiceImage(clusterId, namespace,serviceName ,containersIndexName,containersIndexNameValue,containersIndexImage,containersIndexImageValue);
|
|
|
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
|
|
|
correctImageFlag=true;
|
...
|
...
|
@@ -220,7 +236,7 @@ public class DockerServerDeployService { |
|
|
/**
|
|
|
* 回滚
|
|
|
*/
|
|
|
public boolean modifyImageStore(String clusterId, String namespace, String serviceName,JSONArray containerJa,String rollbackImageStore){
|
|
|
public boolean rollbackImageStore(String clusterId, String namespace, String serviceName,JSONArray containerJa,String rollbackImageStore){
|
|
|
try{
|
|
|
for(int i=0;i<containerJa.size();i++){
|
|
|
JSONObject jo=containerJa.getJSONObject(i);
|
...
|
...
|
@@ -228,12 +244,14 @@ public class DockerServerDeployService { |
|
|
if(StringUtils.isNotBlank(image)&&image.indexOf("/"+serviceName+":")>0){
|
|
|
int index=image.lastIndexOf(":");
|
|
|
String imageLeft=image.substring(0,index);
|
|
|
String imageLeft_to_imageStore=image.substring(0,image.lastIndexOf("/"+serviceName+":"));
|
|
|
String imageLeft_without_imageStore =imageLeft_to_imageStore.substring(0,imageLeft_to_imageStore.lastIndexOf("/"));
|
|
|
//String imageRight=image.substring(index+1);
|
|
|
|
|
|
String containersIndexName="containers."+i+".containerName";
|
|
|
String containersIndexNameValue=jo.getString("containerName");
|
|
|
String containersIndexImage="containers."+i+".image";
|
|
|
String containersIndexImageValue=imageLeft+":"+rollbackImageStore;
|
|
|
String containersIndexImageValue=imageLeft_without_imageStore+rollbackImageStore;
|
|
|
JSONObject searchResult = txServer.modifyClusterServiceImage(clusterId, namespace,serviceName ,containersIndexName,containersIndexNameValue,containersIndexImage,containersIndexImageValue);
|
|
|
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
|
|
|
return true;
|
...
|
...
|
@@ -260,11 +278,14 @@ public class DockerServerDeployService { |
|
|
}
|
|
|
|
|
|
public static void main(String args[]){
|
|
|
String image="xxxxxxx/fddfdf:wwwxxx";
|
|
|
int index=image.lastIndexOf(":");
|
|
|
String image="xxxxxxx/yoho-online/fddfdf:wwwxxx";
|
|
|
int index=image.lastIndexOf("/"+"fddfdf"+":");
|
|
|
String imageLeft=image.substring(0,index);
|
|
|
String imageRight=image.substring(index+1);
|
|
|
System.out.println(imageLeft);
|
|
|
|
|
|
System.out.println(imageLeft.substring(0,imageLeft.lastIndexOf("/")));
|
|
|
|
|
|
System.out.println(imageRight);
|
|
|
}
|
|
|
} |
...
|
...
|
|