Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
2853f394
Commit
2853f394
authored
Nov 25, 2019
by
dqjdda
Browse files
代码优化
parent
468a092d
Changes
15
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/App.java
View file @
2853f394
...
@@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain;
...
@@ -3,8 +3,11 @@ package me.zhengjie.modules.mnt.domain;
import
lombok.Data
;
import
lombok.Data
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
org.hibernate.annotations.CreationTimestamp
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
/**
* @author zhanghouying
* @author zhanghouying
...
@@ -19,8 +22,8 @@ public class App implements Serializable {
...
@@ -19,8 +22,8 @@ public class App implements Serializable {
* 应用编号
* 应用编号
*/
*/
@Id
@Id
@Column
(
name
=
"id"
)
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Stri
ng
id
;
private
Lo
ng
id
;
/**
/**
* 应用名称
* 应用名称
...
@@ -64,6 +67,9 @@ public class App implements Serializable {
...
@@ -64,6 +67,9 @@ public class App implements Serializable {
@Column
(
name
=
"deploy_script"
)
@Column
(
name
=
"deploy_script"
)
private
String
deployScript
;
private
String
deployScript
;
@CreationTimestamp
private
Timestamp
createTime
;
public
void
copy
(
App
source
){
public
void
copy
(
App
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/Deploy.java
View file @
2853f394
...
@@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil;
...
@@ -5,6 +5,7 @@ import cn.hutool.core.bean.BeanUtil;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
javax.persistence.*
;
import
javax.persistence.*
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Set
;
/**
/**
* @author zhanghouying
* @author zhanghouying
...
@@ -19,20 +20,22 @@ public class Deploy implements Serializable {
...
@@ -19,20 +20,22 @@ public class Deploy implements Serializable {
* 部署编号
* 部署编号
*/
*/
@Id
@Id
@
Column
(
name
=
"id"
)
@
GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Stri
ng
id
;
private
Lo
ng
id
;
/**
/**
* 应用编号
* 应用编号
*/
*/
@Column
(
name
=
"app_id"
)
@ManyToOne
private
String
appId
;
@JoinColumn
(
name
=
"app_id"
)
private
App
app
;
/**
/**
*
IP列表
*
服务器
*/
*/
@Column
(
name
=
"ip"
)
@ManyToMany
private
String
ip
;
@JoinTable
(
name
=
"mnt_deploy_server"
,
joinColumns
=
{
@JoinColumn
(
name
=
"deploy_id"
,
referencedColumnName
=
"id"
)},
inverseJoinColumns
=
{
@JoinColumn
(
name
=
"server_id"
,
referencedColumnName
=
"id"
)})
private
Set
<
ServerDeploy
>
deploys
;
public
void
copy
(
Deploy
source
){
public
void
copy
(
Deploy
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/domain/DeployHistory.java
View file @
2853f394
...
@@ -50,7 +50,7 @@ public class DeployHistory implements Serializable {
...
@@ -50,7 +50,7 @@ public class DeployHistory implements Serializable {
* 部署编号
* 部署编号
*/
*/
@Column
(
name
=
"deploy_id"
,
nullable
=
false
)
@Column
(
name
=
"deploy_id"
,
nullable
=
false
)
private
Stri
ng
deployId
;
private
Lo
ng
deployId
;
public
void
copy
(
DeployHistory
source
){
public
void
copy
(
DeployHistory
source
){
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
BeanUtil
.
copyProperties
(
source
,
this
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
));
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/AppRepository.java
View file @
2853f394
...
@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
...
@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author zhanghouying
* @author zhanghouying
* @date 2019-08-24
* @date 2019-08-24
*/
*/
public
interface
AppRepository
extends
JpaRepository
<
App
,
Stri
ng
>,
JpaSpecificationExecutor
<
App
>
{
public
interface
AppRepository
extends
JpaRepository
<
App
,
Lo
ng
>,
JpaSpecificationExecutor
<
App
>
{
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/repository/DeployRepository.java
View file @
2853f394
...
@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
...
@@ -8,5 +8,5 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @author zhanghouying
* @author zhanghouying
* @date 2019-08-24
* @date 2019-08-24
*/
*/
public
interface
DeployRepository
extends
JpaRepository
<
Deploy
,
Stri
ng
>,
JpaSpecificationExecutor
{
public
interface
DeployRepository
extends
JpaRepository
<
Deploy
,
Lo
ng
>,
JpaSpecificationExecutor
<
Deploy
>
{
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/AppController.java
View file @
2853f394
...
@@ -59,7 +59,7 @@ public class AppController {
...
@@ -59,7 +59,7 @@ public class AppController {
@ApiOperation
(
value
=
"删除App"
)
@ApiOperation
(
value
=
"删除App"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"@el.check('app:del')"
)
@PreAuthorize
(
"@el.check('app:del')"
)
public
ResponseEntity
delete
(
@PathVariable
Stri
ng
id
){
public
ResponseEntity
delete
(
@PathVariable
Lo
ng
id
){
appService
.
delete
(
id
);
appService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/rest/DeployController.java
View file @
2853f394
...
@@ -66,7 +66,7 @@ public class DeployController {
...
@@ -66,7 +66,7 @@ public class DeployController {
@ApiOperation
(
value
=
"删除Deploy"
)
@ApiOperation
(
value
=
"删除Deploy"
)
@DeleteMapping
(
value
=
"/{id}"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"@el.check('deploy:del')"
)
@PreAuthorize
(
"@el.check('deploy:del')"
)
public
ResponseEntity
delete
(
@PathVariable
Stri
ng
id
){
public
ResponseEntity
delete
(
@PathVariable
Lo
ng
id
){
deployService
.
delete
(
id
);
deployService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
...
@@ -76,7 +76,7 @@ public class DeployController {
...
@@ -76,7 +76,7 @@ public class DeployController {
@PostMapping
(
value
=
"/upload"
)
@PostMapping
(
value
=
"/upload"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
@PreAuthorize
(
"@el.check('deploy:edit')"
)
public
ResponseEntity
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
public
ResponseEntity
upload
(
@RequestBody
MultipartFile
file
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
Stri
ng
id
=
request
.
getParameter
(
"id"
);
Lo
ng
id
=
Long
.
valueOf
(
request
.
getParameter
(
"id"
)
)
;
String
fileName
=
""
;
String
fileName
=
""
;
if
(
file
!=
null
){
if
(
file
!=
null
){
fileName
=
file
.
getOriginalFilename
();
fileName
=
file
.
getOriginalFilename
();
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/AppService.java
View file @
2853f394
...
@@ -31,7 +31,7 @@ public interface AppService {
...
@@ -31,7 +31,7 @@ public interface AppService {
* @param id
* @param id
* @return
* @return
*/
*/
AppDTO
findById
(
Stri
ng
id
);
AppDTO
findById
(
Lo
ng
id
);
/**
/**
* create
* create
...
@@ -50,5 +50,5 @@ public interface AppService {
...
@@ -50,5 +50,5 @@ public interface AppService {
* delete
* delete
* @param id
* @param id
*/
*/
void
delete
(
Stri
ng
id
);
void
delete
(
Lo
ng
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/DeployService.java
View file @
2853f394
...
@@ -32,7 +32,7 @@ public interface DeployService {
...
@@ -32,7 +32,7 @@ public interface DeployService {
* @param id
* @param id
* @return
* @return
*/
*/
DeployDTO
findById
(
Stri
ng
id
);
DeployDTO
findById
(
Lo
ng
id
);
/**
/**
* create
* create
...
@@ -54,7 +54,7 @@ public interface DeployService {
...
@@ -54,7 +54,7 @@ public interface DeployService {
* @CacheEvict(allEntries = true)
* @CacheEvict(allEntries = true)
* @param id
* @param id
*/
*/
void
delete
(
Stri
ng
id
);
void
delete
(
Lo
ng
id
);
/**
/**
* 部署文件到服务器
* 部署文件到服务器
...
@@ -62,7 +62,7 @@ public interface DeployService {
...
@@ -62,7 +62,7 @@ public interface DeployService {
* @param appId
* @param appId
* @return
* @return
*/
*/
public
String
deploy
(
String
fileSavePath
,
Stri
ng
appId
);
public
String
deploy
(
String
fileSavePath
,
Lo
ng
appId
);
/**
/**
* 查询部署状态
* 查询部署状态
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppDTO.java
View file @
2853f394
...
@@ -3,6 +3,7 @@ package me.zhengjie.modules.mnt.service.dto;
...
@@ -3,6 +3,7 @@ package me.zhengjie.modules.mnt.service.dto;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.sql.Timestamp
;
/**
/**
...
@@ -52,4 +53,6 @@ public class AppDTO implements Serializable {
...
@@ -52,4 +53,6 @@ public class AppDTO implements Serializable {
*/
*/
private
String
deployScript
;
private
String
deployScript
;
private
Timestamp
createTime
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/AppQueryCriteria.java
View file @
2853f394
...
@@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto;
...
@@ -3,6 +3,9 @@ package me.zhengjie.modules.mnt.service.dto;
import
lombok.Data
;
import
lombok.Data
;
import
me.zhengjie.annotation.Query
;
import
me.zhengjie.annotation.Query
;
import
java.sql.Timestamp
;
import
java.util.List
;
/**
/**
* @author zhanghouying
* @author zhanghouying
* @date 2019-08-24
* @date 2019-08-24
...
@@ -15,4 +18,7 @@ public class AppQueryCriteria{
...
@@ -15,4 +18,7 @@ public class AppQueryCriteria{
*/
*/
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
@Query
(
type
=
Query
.
Type
.
INNER_LIKE
)
private
String
name
;
private
String
name
;
@Query
(
type
=
Query
.
Type
.
BETWEEN
)
private
List
<
Timestamp
>
createTime
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployDTO.java
View file @
2853f394
...
@@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto;
...
@@ -2,6 +2,7 @@ package me.zhengjie.modules.mnt.service.dto;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Set
;
/**
/**
...
@@ -16,16 +17,12 @@ public class DeployDTO implements Serializable {
...
@@ -16,16 +17,12 @@ public class DeployDTO implements Serializable {
*/
*/
private
String
id
;
private
String
id
;
/**
private
AppDTO
app
;
* 应用编号
*/
private
String
appId
;
/**
/**
*
IP列表
*
服务器
*/
*/
private
String
ip
;
private
Set
<
ServerDeployDTO
>
deploys
;
/**
/**
* 服务状态
* 服务状态
...
...
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/dto/DeployHistoryDTO.java
View file @
2853f394
...
@@ -39,5 +39,5 @@ public class DeployHistoryDTO implements Serializable {
...
@@ -39,5 +39,5 @@ public class DeployHistoryDTO implements Serializable {
/**
/**
* 部署编号
* 部署编号
*/
*/
private
Stri
ng
deployId
;
private
Lo
ng
deployId
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/AppServiceImpl.java
View file @
2853f394
package
me.zhengjie.modules.mnt.service.impl
;
package
me.zhengjie.modules.mnt.service.impl
;
import
cn.hutool.core.util.IdUtil
;
import
me.zhengjie.modules.mnt.domain.App
;
import
me.zhengjie.modules.mnt.domain.App
;
import
me.zhengjie.modules.mnt.repository.AppRepository
;
import
me.zhengjie.modules.mnt.repository.AppRepository
;
import
me.zhengjie.modules.mnt.service.AppService
;
import
me.zhengjie.modules.mnt.service.AppService
;
...
@@ -15,7 +14,6 @@ import org.springframework.data.domain.Pageable;
...
@@ -15,7 +14,6 @@ import org.springframework.data.domain.Pageable;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Optional
;
import
java.util.Optional
;
/**
/**
...
@@ -47,7 +45,7 @@ public class AppServiceImpl implements AppService {
...
@@ -47,7 +45,7 @@ public class AppServiceImpl implements AppService {
}
}
@Override
@Override
public
AppDTO
findById
(
Stri
ng
id
)
{
public
AppDTO
findById
(
Lo
ng
id
)
{
Optional
<
App
>
app
=
appRepository
.
findById
(
id
);
Optional
<
App
>
app
=
appRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
app
,
"App"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
app
,
"App"
,
"id"
,
id
);
return
appMapper
.
toDto
(
app
.
get
());
return
appMapper
.
toDto
(
app
.
get
());
...
@@ -56,7 +54,6 @@ public class AppServiceImpl implements AppService {
...
@@ -56,7 +54,6 @@ public class AppServiceImpl implements AppService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
AppDTO
create
(
App
resources
)
{
public
AppDTO
create
(
App
resources
)
{
resources
.
setId
(
IdUtil
.
fastUUID
());
return
appMapper
.
toDto
(
appRepository
.
save
(
resources
));
return
appMapper
.
toDto
(
appRepository
.
save
(
resources
));
}
}
...
@@ -72,7 +69,7 @@ public class AppServiceImpl implements AppService {
...
@@ -72,7 +69,7 @@ public class AppServiceImpl implements AppService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Stri
ng
id
)
{
public
void
delete
(
Lo
ng
id
)
{
appRepository
.
deleteById
(
id
);
appRepository
.
deleteById
(
id
);
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/mnt/service/impl/DeployServiceImpl.java
View file @
2853f394
...
@@ -5,8 +5,10 @@ import cn.hutool.core.date.DateUtil;
...
@@ -5,8 +5,10 @@ import cn.hutool.core.date.DateUtil;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.IdUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.mnt.domain.App
;
import
me.zhengjie.modules.mnt.domain.Deploy
;
import
me.zhengjie.modules.mnt.domain.Deploy
;
import
me.zhengjie.modules.mnt.domain.DeployHistory
;
import
me.zhengjie.modules.mnt.domain.DeployHistory
;
import
me.zhengjie.modules.mnt.domain.ServerDeploy
;
import
me.zhengjie.modules.mnt.repository.DeployRepository
;
import
me.zhengjie.modules.mnt.repository.DeployRepository
;
import
me.zhengjie.modules.mnt.service.*
;
import
me.zhengjie.modules.mnt.service.*
;
import
me.zhengjie.modules.mnt.service.dto.*
;
import
me.zhengjie.modules.mnt.service.dto.*
;
...
@@ -32,6 +34,7 @@ import java.io.IOException;
...
@@ -32,6 +34,7 @@ import java.io.IOException;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.Set
;
/**
/**
* @author zhanghouying
* @author zhanghouying
...
@@ -74,7 +77,7 @@ public class DeployServiceImpl implements DeployService {
...
@@ -74,7 +77,7 @@ public class DeployServiceImpl implements DeployService {
}
}
@Override
@Override
public
DeployDTO
findById
(
Stri
ng
id
)
{
public
DeployDTO
findById
(
Lo
ng
id
)
{
Optional
<
Deploy
>
Deploy
=
deployRepository
.
findById
(
id
);
Optional
<
Deploy
>
Deploy
=
deployRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
Deploy
,
"Deploy"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
Deploy
,
"Deploy"
,
"id"
,
id
);
return
deployMapper
.
toDto
(
Deploy
.
get
());
return
deployMapper
.
toDto
(
Deploy
.
get
());
...
@@ -83,7 +86,6 @@ public class DeployServiceImpl implements DeployService {
...
@@ -83,7 +86,6 @@ public class DeployServiceImpl implements DeployService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
DeployDTO
create
(
Deploy
resources
)
{
public
DeployDTO
create
(
Deploy
resources
)
{
resources
.
setId
(
IdUtil
.
simpleUUID
());
return
deployMapper
.
toDto
(
deployRepository
.
save
(
resources
));
return
deployMapper
.
toDto
(
deployRepository
.
save
(
resources
));
}
}
...
@@ -99,12 +101,12 @@ public class DeployServiceImpl implements DeployService {
...
@@ -99,12 +101,12 @@ public class DeployServiceImpl implements DeployService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Stri
ng
id
)
{
public
void
delete
(
Lo
ng
id
)
{
deployRepository
.
deleteById
(
id
);
deployRepository
.
deleteById
(
id
);
}
}
@Override
@Override
public
String
deploy
(
String
fileSavePath
,
Stri
ng
id
)
{
public
String
deploy
(
String
fileSavePath
,
Lo
ng
id
)
{
return
deployApp
(
fileSavePath
,
id
);
return
deployApp
(
fileSavePath
,
id
);
}
}
...
@@ -113,14 +115,14 @@ public class DeployServiceImpl implements DeployService {
...
@@ -113,14 +115,14 @@ public class DeployServiceImpl implements DeployService {
* @param id
* @param id
* @return
* @return
*/
*/
private
String
deployApp
(
String
fileSavePath
,
Stri
ng
id
)
{
private
String
deployApp
(
String
fileSavePath
,
Lo
ng
id
)
{
DeployDTO
deploy
=
findById
(
id
);
DeployDTO
deploy
=
findById
(
id
);
if
(
deploy
==
null
)
{
if
(
deploy
==
null
)
{
sendMsg
(
"部署信息不存在"
,
MsgType
.
ERROR
);
sendMsg
(
"部署信息不存在"
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"部署信息不存在"
);
throw
new
BadRequestException
(
"部署信息不存在"
);
}
}
AppDTO
app
=
appService
.
findById
(
deploy
.
getApp
Id
()
);
AppDTO
app
=
deploy
.
getApp
(
);
if
(
app
==
null
)
{
if
(
app
==
null
)
{
sendMsg
(
"包对应应用信息不存在"
,
MsgType
.
ERROR
);
sendMsg
(
"包对应应用信息不存在"
,
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"包对应应用信息不存在"
);
throw
new
BadRequestException
(
"包对应应用信息不存在"
);
...
@@ -130,42 +132,44 @@ public class DeployServiceImpl implements DeployService {
...
@@ -130,42 +132,44 @@ public class DeployServiceImpl implements DeployService {
String
uploadPath
=
app
.
getUploadPath
();
String
uploadPath
=
app
.
getUploadPath
();
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
String
msg
=
""
;
String
msg
=
""
;
String
ip
=
deploy
.
getIp
();
Set
<
ServerDeployDTO
>
deploys
=
deploy
.
getDeploys
();
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
ip
);
for
(
ServerDeployDTO
deployDTO
:
deploys
)
{
//判断是否第一次部署
String
ip
=
deployDTO
.
getIp
();
boolean
flag
=
checkFile
(
executeShellUtil
,
app
);
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
ip
);
//第一步要确认服务器上有这个目录
//判断是否第一次部署
executeShellUtil
.
execute
(
"mkdir -p "
+
uploadPath
);
boolean
flag
=
checkFile
(
executeShellUtil
,
app
);
//上传文件
//第一步要确认服务器上有这个目录
msg
=
String
.
format
(
"登陆到服务器:%s"
,
ip
);
executeShellUtil
.
execute
(
"mkdir -p "
+
uploadPath
);
ScpClientUtil
scpClientUtil
=
getScpClientUtil
(
ip
);
//上传文件
log
.
info
(
msg
);
msg
=
String
.
format
(
"登陆到服务器:%s"
,
ip
);
sendMsg
(
msg
,
MsgType
.
INFO
);
ScpClientUtil
scpClientUtil
=
getScpClientUtil
(
ip
);
msg
=
String
.
format
(
"上传文件到服务器:%s<br>目录:%s下"
,
ip
,
uploadPath
);
log
.
info
(
msg
);
sendMsg
(
msg
,
MsgType
.
INFO
);
sendMsg
(
msg
,
MsgType
.
INFO
);
scpClientUtil
.
putFile
(
fileSavePath
,
uploadPath
);
msg
=
String
.
format
(
"上传文件到服务器:%s<br>目录:%s下"
,
ip
,
uploadPath
);
if
(
flag
)
{
sendMsg
(
msg
,
MsgType
.
INFO
);
sendMsg
(
"停止原来应用"
,
MsgType
.
INFO
);
scpClientUtil
.
putFile
(
fileSavePath
,
uploadPath
);
//停止应用
if
(
flag
)
{
stopApp
(
port
,
executeShellUtil
);
sendMsg
(
"停止原来应用"
,
MsgType
.
INFO
);
sendMsg
(
"备份原来应用"
,
MsgType
.
INFO
);
//停止应用
//备份应用
stopApp
(
port
,
executeShellUtil
);
backupApp
(
executeShellUtil
,
ip
,
app
.
getDeployPath
(),
app
.
getName
(),
app
.
getBackupPath
(),
id
);
sendMsg
(
"备份原来应用"
,
MsgType
.
INFO
);
//备份应用
backupApp
(
executeShellUtil
,
ip
,
app
.
getDeployPath
(),
app
.
getName
(),
app
.
getBackupPath
(),
id
);
}
sendMsg
(
"部署应用"
,
MsgType
.
INFO
);
//部署文件,并启动应用
String
deployScript
=
app
.
getDeployScript
();
executeShellUtil
.
execute
(
deployScript
);
sendMsg
(
"启动应用"
,
MsgType
.
INFO
);
String
startScript
=
app
.
getStartScript
();
executeShellUtil
.
execute
(
startScript
);
//只有过5秒才能知道到底是不是启动成功了。
sleep
(
5
);
boolean
result
=
checkIsRunningStatus
(
port
,
executeShellUtil
);
sb
.
append
(
"服务器:"
).
append
(
deployDTO
.
getName
()).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sendResultMsg
(
result
,
sb
);
}
}
sendMsg
(
"部署应用"
,
MsgType
.
INFO
);
//部署文件,并启动应用
String
deployScript
=
app
.
getDeployScript
();
executeShellUtil
.
execute
(
deployScript
);
sendMsg
(
"启动应用"
,
MsgType
.
INFO
);
String
startScript
=
app
.
getStartScript
();
executeShellUtil
.
execute
(
startScript
);
//只有过5秒才能知道到底是不是启动成功了。
sleep
(
5
);
boolean
result
=
checkIsRunningStatus
(
port
,
executeShellUtil
);
sb
.
append
(
"服务器:"
).
append
(
ip
).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sendResultMsg
(
result
,
sb
);
return
"部署结束"
;
return
"部署结束"
;
}
}
...
@@ -177,7 +181,7 @@ public class DeployServiceImpl implements DeployService {
...
@@ -177,7 +181,7 @@ public class DeployServiceImpl implements DeployService {
}
}
}
}
private
void
backupApp
(
ExecuteShellUtil
executeShellUtil
,
String
ip
,
String
fileSavePath
,
String
appName
,
String
backupPath
,
Stri
ng
id
)
{
private
void
backupApp
(
ExecuteShellUtil
executeShellUtil
,
String
ip
,
String
fileSavePath
,
String
appName
,
String
backupPath
,
Lo
ng
id
)
{
String
deployDate
=
DateUtil
.
format
(
new
Date
(),
DatePattern
.
PURE_DATETIME_PATTERN
);
String
deployDate
=
DateUtil
.
format
(
new
Date
(),
DatePattern
.
PURE_DATETIME_PATTERN
);
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
if
(!
backupPath
.
endsWith
(
FILE_SEPARATOR
))
{
if
(!
backupPath
.
endsWith
(
FILE_SEPARATOR
))
{
...
@@ -241,21 +245,22 @@ public class DeployServiceImpl implements DeployService {
...
@@ -241,21 +245,22 @@ public class DeployServiceImpl implements DeployService {
@Override
@Override
public
String
serverStatus
(
Deploy
resources
)
{
public
String
serverStatus
(
Deploy
resources
)
{
String
ip
=
resources
.
getIp
();
Set
<
ServerDeploy
>
serverDeploys
=
resources
.
getDeploys
();
String
appId
=
resources
.
getAppId
();
App
app
=
resources
.
getApp
();
AppDTO
app
=
appService
.
findById
(
appId
);
for
(
ServerDeploy
serverDeploy
:
serverDeploys
)
{
StringBuffer
sb
=
new
StringBuffer
();
StringBuilder
sb
=
new
StringBuilder
();
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
ip
);
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
serverDeploy
.
getIp
());
sb
.
append
(
"服务器:"
).
append
(
ip
).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sb
.
append
(
"服务器:"
).
append
(
serverDeploy
.
getName
()).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
if
(
result
)
{
if
(
result
)
{
sb
.
append
(
"<br>正在运行"
);
sb
.
append
(
"<br>正在运行"
);
sendMsg
(
sb
.
toString
(),
MsgType
.
INFO
);
sendMsg
(
sb
.
toString
(),
MsgType
.
INFO
);
}
else
{
}
else
{
sb
.
append
(
"<br>已停止!"
);
sb
.
append
(
"<br>已停止!"
);
sendMsg
(
sb
.
toString
(),
MsgType
.
ERROR
);
sendMsg
(
sb
.
toString
(),
MsgType
.
ERROR
);
}
log
.
info
(
sb
.
toString
());
}
}
log
.
info
(
sb
.
toString
());
return
"执行完毕"
;
return
"执行完毕"
;
}
}
...
@@ -277,21 +282,22 @@ public class DeployServiceImpl implements DeployService {
...
@@ -277,21 +282,22 @@ public class DeployServiceImpl implements DeployService {
*/
*/
@Override
@Override
public
String
startServer
(
Deploy
resources
)
{
public
String
startServer
(
Deploy
resources
)
{
String
ip
=
resources
.
getIp
();
Set
<
ServerDeploy
>
deploys
=
resources
.
getDeploys
();
String
appId
=
resources
.
getAppId
();
App
app
=
resources
.
getApp
();
AppDTO
app
=
appService
.
findById
(
appId
);
for
(
ServerDeploy
deploy
:
deploys
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
ip
);
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
deploy
.
getIp
());
//为了防止重复启动,这里先停止应用
//为了防止重复启动,这里先停止应用
stopApp
(
app
.
getPort
(),
executeShellUtil
);
stopApp
(
app
.
getPort
(),
executeShellUtil
);
sb
.
append
(
"服务器:"
).
append
(
ip
).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sb
.
append
(
"服务器:"
).
append
(
deploy
.
getName
()).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sendMsg
(
"下发启动命令"
,
MsgType
.
INFO
);
sendMsg
(
"下发启动命令"
,
MsgType
.
INFO
);
executeShellUtil
.
execute
(
app
.
getStartScript
());
executeShellUtil
.
execute
(
app
.
getStartScript
());
//停止3秒,防止应用没有启动完成
//停止3秒,防止应用没有启动完成
sleep
(
3
);
sleep
(
3
);
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
sendResultMsg
(
result
,
sb
);
sendResultMsg
(
result
,
sb
);
log
.
info
(
sb
.
toString
());
log
.
info
(
sb
.
toString
());
}
return
"执行完毕"
;
return
"执行完毕"
;
}
}
...
@@ -302,34 +308,35 @@ public class DeployServiceImpl implements DeployService {
...
@@ -302,34 +308,35 @@ public class DeployServiceImpl implements DeployService {
*/
*/
@Override
@Override
public
String
stopServer
(
Deploy
resources
)
{
public
String
stopServer
(
Deploy
resources
)
{
String
ip
=
resources
.
getIp
();
Set
<
ServerDeploy
>
deploys
=
resources
.
getDeploys
();
String
appId
=
resources
.
getAppId
();
App
app
=
resources
.
getApp
();
AppDTO
app
=
appService
.
findById
(
appId
);
for
(
ServerDeploy
deploy
:
deploys
)
{
StringBuffer
sb
=
new
StringBuffer
();
StringBuffer
sb
=
new
StringBuffer
();
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
ip
);
ExecuteShellUtil
executeShellUtil
=
getExecuteShellUtil
(
deploy
.
getIp
());
sb
.
append
(
"服务器:"
).
append
(
ip
).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sb
.
append
(
"服务器:"
).
append
(
deploy
.
getName
()).
append
(
"<br>应用:"
).
append
(
app
.
getName
());
sendMsg
(
"下发停止命令"
,
MsgType
.
INFO
);
sendMsg
(
"下发停止命令"
,
MsgType
.
INFO
);
//停止应用
//停止应用
stopApp
(
app
.
getPort
(),
executeShellUtil
);
stopApp
(
app
.
getPort
(),
executeShellUtil
);
sleep
(
1
);
sleep
(
1
);
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
boolean
result
=
checkIsRunningStatus
(
app
.
getPort
(),
executeShellUtil
);
if
(
result
)
{
if
(
result
)
{
sb
.
append
(
"<br>关闭失败!"
);
sb
.
append
(
"<br>关闭失败!"
);
sendMsg
(
sb
.
toString
(),
MsgType
.
ERROR
);
sendMsg
(
sb
.
toString
(),
MsgType
.
ERROR
);
}
else
{
}
else
{
sb
.
append
(
"<br>关闭成功!"
);
sb
.
append
(
"<br>关闭成功!"
);
sendMsg
(
sb
.
toString
(),
MsgType
.
INFO
);
sendMsg
(
sb
.
toString
(),
MsgType
.
INFO
);
}
log
.
info
(
sb
.
toString
());
}
}
log
.
info
(
sb
.
toString
());
return
"执行完毕"
;
return
"执行完毕"
;
}
}
@Override
@Override
public
String
serverReduction
(
DeployHistory
resources
)
{
public
String
serverReduction
(
DeployHistory
resources
)
{
Stri
ng
deployId
=
resources
.
getDeployId
();
Lo
ng
deployId
=
resources
.
getDeployId
();
Deploy
deployInfo
=
deployRepository
.
findById
(
deployId
).
get
();
Deploy
deployInfo
=
deployRepository
.
findById
(
deployId
).
get
();
String
deployDate
=
resources
.
getDeployDate
();
String
deployDate
=
resources
.
getDeployDate
();
App
DTO
app
=
appService
.
findById
(
deployInfo
.
getApp
Id
()
);
App
app
=
deployInfo
.
getApp
(
);
if
(
app
==
null
)
{
if
(
app
==
null
)
{
sendMsg
(
"应用信息不存在:"
+
resources
.
getAppName
(),
MsgType
.
ERROR
);
sendMsg
(
"应用信息不存在:"
+
resources
.
getAppName
(),
MsgType
.
ERROR
);
throw
new
BadRequestException
(
"应用信息不存在:"
+
resources
.
getAppName
());
throw
new
BadRequestException
(
"应用信息不存在:"
+
resources
.
getAppName
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment