inputStream.start();
// 等待ffmpeg命令执行完
int exit = 0;
try {
exit = ffmpeg.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
LOG.info(“—执行结果:—” + (exit == 0 ? “【成功】” : “【失败】”));
if (exit == 0) {
originFile = new File(filePath);
if(originFile.exists()){
originFile.delete();
}
}
return exit;
}
/**
• 获取文件后缀
• 
• @param fileName
• @return java.lang.String
• @author zxzhang
• @date 2019/12/10
*/
public String getExt(String fileName) {
return fileName.substring(fileName.lastIndexOf(“.”) + 1);
}
/**
• 获取文件所在目录
• 
• @param filePath
• @return java.lang.String
• @author zxzhang
• @date 2019/12/10
*/
public String getFileDir(String filePath) {
return filePath.substring(0, filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR));
}
/**
• 获取文件名
• 
• @param filePath
• @return java.lang.String
• @author zxzhang
• @date 2019/12/10
*/
public String getFileName(String filePath) {
return filePath.substring(filePath.lastIndexOf(BootstrapConst.PATH_SEPARATOR) + 1, filePath.lastIndexOf(“.”));
}
}
class PrintStream extends Thread {
java.io.InputStream __is = null;
public PrintStream(java.io.InputStream is) {
__is = is;
}
@Override
public void run() {
try {
while (this != null) {
int _ch = __is.read();
if (_ch != -1) {
System.out.print((char) _ch);
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
2、BootstrapConst类
package com.openailab.oascloud.file.common.consts;
/**
• @Classname: com.openailab.oascloud.security.common.consts.BootstrapConst
• @Description: 简单常量定义
• @Author: zxzhang
• @Date: 2019/10/8
*/
public class BootstrapConst {
/**
• 文件缓冲区大小
*/
public static final Integer INPUT_BUFFER_SIZE = 8192;
/**
• 文件分隔符
*/
public static final char PATH_SEPARATOR = ‘/’;
/**
• 文件点
*/
public static final char SPOT = ‘.’;
/**
• 常量一
*/
public static final Integer ONE = 1;
/**
• 成功
*/
public static final Integer SUCCESS = 1;
/**
• 失败
*/
public static final Integer FAIL = 0;
/**
• true
*/
public static final Boolean TRUE = true;
/**
• false
*/
public static final Boolean FALSE = false;
}
三、FFMPeg DockerFile实现
首先我们构建具有JDK1.8和FFMPeg环境的镜像
FROM jrottenberg/ffmpeg:centos
MAINTAINER oas.cloud
ADD jdk-8u231-linux-x64.tar.gz /usr/local/
ENV JAVA_HOME /usr/local/jdk1.8.0_231
ENV CLASSPATH JAVA_HOME/lib/tools.jarENV PATH JAVA_HOME/binWORKDIR /usr/local/oas/
然后将上述文件构建出的镜像的tag打为我们自己的镜像仓库地址,改为 10.12.1.202:8088/oascloud/ffmpeg:v1.0,我们的应用程序就可以以上述镜像文件(10.12.1.202:8088/oascloud/ffmpeg:v1.0)为基础构建出新的应用程序镜像,应用程序的DockerFile如下:
FROM 10.12.1.202:8088/oascloud/ffmpeg:v1.0
MAINTAINER oas.cloud
ENV LC_ALL=zh_CN.utf8
ENV LANG=zh_CN.utf8
ENV LANGUAGE=zh_CN.utf8
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
ARG JAR_FILE
COPY ${JAR_FILE} /usr/local/oas/
WORKDIR /usr/local/oas/
代码结构如下:

Springboot 集成Flyway_java

附上Kubernetes编排文件,deploy.yaml内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
name: openailab-data-file-management
namespace: oas-tengine2dev
labels:
name: openailab-data-file-management
spec:
replicas: 1
selector:
matchLabels:
name: openailab-data-file-management
template:
metadata:
labels:
name: openailab-data-file-management
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
• matchExpressions:
• key: env
operator: In
values:
• tengine2dev
containers:
• name: openailab-data-file-management
image: 10.12.1.202:8088/tengine2/openailab-data-file-management:latest
env:
• name: APOLLO_APP_ID
value: ‘tengine2-data-file-management’
• name: APOLLO_EUREKA_URI
value: ‘http://10.98.100.95:8080/’
• name: APOLLO_NAMESPACE
value: ‘application’
• name: SPRING_EUREKA_URI
value: ‘http://10.111.176.222:8080/eureka/’
volumeMounts:
• name: openailab-data-file-management
mountPath: /usr/local/logs
• name: file
mountPath: /usr/local/oas/file
command: [‘sh’,‘-c’,‘java -server -Xms2048m -Xmx3072m -Djava.io.tmpdir=/var/tmp -Duser.timezone=Asia/Shanghai -jar openailab-data-file-management-*.jar --server.port=8080 --spring.profiles.active=remote’]
ports:
• containerPort: 8080
resources:
requests:
memory: 256Mi
cpu: 150m
limits:
memory: 2048Mi
cpu: 300m
initContainers:
• name: init-apollo
image: busybox
command: [‘sh’, ‘-c’]
args:
• echo Prepare to apollo initialize…;
until nc -w 1 -z 10.98.100.95 8080;
do echo Waiting for eureka initialization to complete…; sleep 10; done;
echo Eureka is ready.;
until nc -w 1 -z 10.98.100.95 8090;
do echo Waiting for admin initialization to complete…; sleep 10; done;
echo Admin is ready.;
echo Apollo Initialization successful!;
volumes:
• name: openailab-data-file-management
hostPath:
path: /usr/local/logs
• name: file
hostPath:
path: /usr/local/oas/file
svc.yaml内容如下:
apiVersion: v1
kind: Service
metadata:
name: openailab-data-file-management
namespace: oas-tengine2dev
labels: