mirror of
https://github.com/ctripcorp/zeus.git
synced 2024-09-22 00:26:05 +08:00
update activate
This commit is contained in:
parent
f08bf83890
commit
ecb8566fc0
|
@ -59,59 +59,25 @@ public class ActivateResource {
|
|||
@GET
|
||||
@Path("/activate")
|
||||
@Authorize(name="activate")
|
||||
public Response list(@Context HttpServletRequest request,@Context HttpHeaders hh,@QueryParam("slbName") List<String> slbNames, @QueryParam("appName") List<String> appNames)throws Exception{
|
||||
return activateAll(slbNames,appNames,hh);
|
||||
public Response activateByName(@Context HttpServletRequest request,@Context HttpHeaders hh,@QueryParam("slbName") List<String> slbNames, @QueryParam("GroupName") List<String> groupNames)throws Exception{
|
||||
// return activateAll(slbNames,groupNames,hh);
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@GET
|
||||
@Path("/activate")
|
||||
@Authorize(name="activate")
|
||||
public Response activate(@Context HttpServletRequest request,@Context HttpHeaders hh, String req) throws Exception {
|
||||
ConfReq confreq = null;
|
||||
if (hh.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) {
|
||||
confreq = DefaultSaxParser.parseEntity(ConfReq.class, req);
|
||||
}else //if (hh.getMediaType().equals(MediaType.APPLICATION_JSON_TYPE))
|
||||
{
|
||||
confreq = DefaultJsonParser.parse(ConfReq.class, req);
|
||||
public Response activateById(@Context HttpServletRequest request,@Context HttpHeaders hh,@QueryParam("slbId") List<Long> slbIds, @QueryParam("GroupId") List<Long> groupIds)throws Exception{
|
||||
return activateAll(slbIds,groupIds,hh);
|
||||
}
|
||||
|
||||
AssertUtils.isNull(confreq,"the parameter is illegal!\n request parameter: "+req);
|
||||
|
||||
List<String> appNameList = Lists.transform(confreq.getConfAppNames(),new Function<ConfAppName, String>(){
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable ConfAppName confAppName) {
|
||||
try {
|
||||
return confAppName.getAppname();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
private Response activateAll(List<Long> slbIds,List<Long> groupIds, HttpHeaders hh)throws Exception{
|
||||
|
||||
List<String> slbNameList = Lists.transform(confreq.getConfSlbNames(),new Function<ConfSlbName, String>(){
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(@Nullable ConfSlbName slbName) {
|
||||
try {
|
||||
return slbName.getSlbname();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return activateAll(slbNameList,appNameList,hh);
|
||||
}
|
||||
|
||||
private Response activateAll(List<String> slbNames,List<String> appNames, HttpHeaders hh)throws Exception{
|
||||
|
||||
AssertUtils.arrertNotEquels(0,slbNames.size()+appNames.size(),"slbName list and appName list are empty!");
|
||||
AssertUtils.arrertNotEquels(0,slbIds.size()+groupIds.size(),"slbIds list and groupIds list are empty!");
|
||||
|
||||
//update active action to conf-slb-active and conf-app-active
|
||||
activateConfService.activate(slbNames,appNames);
|
||||
activateConfService.activate(slbIds,groupIds);
|
||||
|
||||
//find all slbs which need build config
|
||||
Set<String> slbList = buildInfoService.getAllNeededSlb(slbNames, appNames);
|
||||
|
|
|
@ -12,26 +12,26 @@ public interface ActivateService extends Repository {
|
|||
|
||||
/**
|
||||
* update active data by slbname
|
||||
* @param slbname the slb name
|
||||
* @param slbId the slb id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public void activeSlb(String slbname) throws Exception;
|
||||
public void activeSlb(long slbId) throws Exception;
|
||||
/**
|
||||
* update active data by slbname
|
||||
* @param appname the slb name
|
||||
* @param groupId the Group id
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public void activeApp(String appname) throws Exception;
|
||||
public void activeGroup(long groupId) throws Exception;
|
||||
|
||||
/**
|
||||
* update active data by slbnames and appnames
|
||||
* @param slbNames the slb names
|
||||
* @param appNames the app names
|
||||
* @param slbIds the slb ids
|
||||
* @param groupIds the group ids
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public void activate(List<String> slbNames, List<String> appNames)throws Exception;
|
||||
public void activate(List<Long> slbIds, List<Long> groupIds)throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.ctrip.zeus.dal.core.*;
|
|||
import com.ctrip.zeus.model.entity.App;
|
||||
import com.ctrip.zeus.model.entity.AppSlb;
|
||||
import com.ctrip.zeus.model.entity.Archive;
|
||||
import com.ctrip.zeus.model.entity.Group;
|
||||
import com.ctrip.zeus.model.entity.GroupSlb;
|
||||
import com.ctrip.zeus.model.transform.DefaultSaxParser;
|
||||
import com.ctrip.zeus.service.Activate.ActivateService;
|
||||
import com.ctrip.zeus.service.model.ArchiveService;
|
||||
|
@ -26,75 +28,75 @@ import java.util.List;
|
|||
public class ActivateServiceImpl implements ActivateService {
|
||||
|
||||
@Resource
|
||||
private ConfAppActiveDao confAppActiveDao;
|
||||
private ConfGroupActiveDao confGroupActiveDao;
|
||||
@Resource
|
||||
private ConfSlbActiveDao confSlbActiveDao;
|
||||
@Resource
|
||||
private ArchiveService archiveService;
|
||||
@Resource
|
||||
ConfAppSlbActiveDao confAppSlbActiveDao;
|
||||
ConfGroupSlbActiveDao confGroupSlbActiveDao;
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ActivateServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public void activeSlb(String name) throws Exception {
|
||||
public void activeSlb(long slbId) throws Exception {
|
||||
|
||||
Archive archive = archiveService.getLatestSlbArchive(name);
|
||||
Archive archive = archiveService.getLatestSlbArchive(slbId);
|
||||
if (archive==null)
|
||||
{
|
||||
logger.info("getLatestSlbArchive return Null! SlbName: "+name);
|
||||
AssertUtils.isNull(archive,"[Activate]getLatestSlbArchive return Null! SlbName: "+name);
|
||||
logger.info("getLatestSlbArchive return Null! SlbID: "+slbId);
|
||||
AssertUtils.isNull(archive,"[Activate]getLatestSlbArchive return Null! SlbID: "+slbId);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfSlbActiveDo c = new ConfSlbActiveDo().setCreatedTime(new Date());
|
||||
c.setName(archive.getName()).setContent(archive.getContent()).setVersion(archive.getVersion());
|
||||
c.setSlbId(archive.getId()).setContent(archive.getContent()).setVersion(archive.getVersion());
|
||||
confSlbActiveDao.insert(c);
|
||||
|
||||
logger.debug("Conf Slb Active Inserted: [name: "+c.getName()+",Content: "+c.getContent()+",Version: "+c.getVersion()+"]");
|
||||
logger.debug("Conf Slb Active Inserted: [SlbID: "+c.getSlbId()+",Content: "+c.getContent()+",Version: "+c.getVersion()+"]");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeApp(String name) throws Exception {
|
||||
Archive archive = archiveService.getLatestAppArchive(name);
|
||||
public void activeGroup(long groupId) throws Exception {
|
||||
Archive archive = archiveService.getLatestGroupArchive(groupId);
|
||||
if (archive==null)
|
||||
{
|
||||
logger.info("getLatestAppArchive return Null! AppName: "+name);
|
||||
AssertUtils.isNull(archive,"[Activate]getLatestAppArchive return Null! AppName: "+name);
|
||||
logger.info("getLatestAppArchive return Null! GroupID: "+groupId);
|
||||
AssertUtils.isNull(archive,"[Activate]getLatestAppArchive return Null! GroupID: "+groupId);
|
||||
return;
|
||||
}
|
||||
|
||||
ConfAppActiveDo c = new ConfAppActiveDo().setCreatedTime(new Date());
|
||||
c.setName(archive.getName()).setContent(archive.getContent()).setVersion(archive.getVersion());
|
||||
confAppActiveDao.insert(c);
|
||||
ConfGroupActiveDo c = new ConfGroupActiveDo().setCreatedTime(new Date());
|
||||
c.setGroupId(archive.getId()).setContent(archive.getContent()).setVersion(archive.getVersion());
|
||||
confGroupActiveDao.insert(c);
|
||||
|
||||
logger.debug("Conf App Active Inserted: [name: "+c.getName()+",Content: "+c.getContent()+",Version: "+c.getVersion()+"]");
|
||||
logger.debug("Conf Group Active Inserted: [GroupId: "+c.getId()+",Content: "+c.getContent()+",Version: "+c.getVersion()+"]");
|
||||
|
||||
|
||||
App app = DefaultSaxParser.parseEntity(App.class, c.getContent());
|
||||
Group group = DefaultSaxParser.parseEntity(Group.class, c.getContent());
|
||||
|
||||
AssertUtils.isNull(app,"App_ctive.content XML is illegal!");
|
||||
AssertUtils.isNull(group,"App_ctive.content XML is illegal!");
|
||||
|
||||
confAppSlbActiveDao.deleteByAppName(new ConfAppSlbActiveDo().setAppName(name));
|
||||
confGroupSlbActiveDao.deleteByGroupId(new ConfGroupSlbActiveDo().setGroupId(groupId));
|
||||
|
||||
for (AppSlb appSlb:app.getAppSlbs())
|
||||
for (GroupSlb groupSlb:group.getGroupSlbs())
|
||||
{
|
||||
confAppSlbActiveDao.insert(new ConfAppSlbActiveDo().setAppName(name)
|
||||
.setSlbVirtualServerName(appSlb.getVirtualServer().getName())
|
||||
.setPriority(appSlb.getPriority())
|
||||
.setSlbName(appSlb.getSlbName()).setDataChangeLastTime(new Date()));
|
||||
confGroupSlbActiveDao.insert(new ConfGroupSlbActiveDo().setGroupId(groupId)
|
||||
.setPriority(groupSlb.getPriority())
|
||||
.setSlbId(groupSlb.getSlbName()).setDataChangeLastTime(new Date()))
|
||||
.setSlbVirtualServerId(groupSlb.getVirtualServer().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate(List<String> slbNames, List<String> appNames) throws Exception {
|
||||
for (String slbName : slbNames) {
|
||||
activeSlb(slbName);
|
||||
public void activate(List<Long> slbIds, List<Long> groupIds) throws Exception {
|
||||
for (Long slbId : slbIds) {
|
||||
activeSlb(slbId);
|
||||
}
|
||||
for (String appName : appNames) {
|
||||
activeApp(appName);
|
||||
for (Long groupId : groupIds) {
|
||||
activeGroup(groupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<entities do-package="com.ctrip.zeus.dal.core" gen="true" do-class-suffix="Do">
|
||||
<entity name="conf-app-active" table="conf_app_active" alias="caa">
|
||||
<var name="names" value-type="String[]"/>
|
||||
<entity name="conf-group-active" table="conf_group_active" alias="cga">
|
||||
<var name="ids" value-type="Long[]"/>
|
||||
<query-defs>
|
||||
<query name="insert" type="INSERT">
|
||||
<statement>
|
||||
|
@ -15,20 +15,20 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="find-all-by-names" type="SELECT" multiple="true">
|
||||
<param name="names"/>
|
||||
<query name="find-all-by-group-ids" type="SELECT" multiple="true">
|
||||
<param name="ids"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
WHERE <FIELD name='name'/> in <IN>${names}</IN>
|
||||
WHERE <FIELD name='group-id'/> in <IN>${ids}</IN>
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
</query-defs>
|
||||
</entity>
|
||||
<entity name="conf-slb-active" table="conf_slb_active" alias="csa">
|
||||
<var name="names" value-type="String[]"/>
|
||||
<var name="ids" value-type="Long[]"/>
|
||||
<query-defs>
|
||||
<query name="insert" type="INSERT">
|
||||
<statement>
|
||||
|
@ -42,30 +42,30 @@
|
|||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="find-by-name" type="SELECT">
|
||||
<param name="name"/>
|
||||
<query name="find-by-slb-id" type="SELECT">
|
||||
<param name="id"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
WHERE <FIELD name='name'/> = ${name}
|
||||
WHERE <FIELD name='slb-id'/> = ${id}
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="find-all-by-names" type="SELECT" multiple="true">
|
||||
<param name="names"/>
|
||||
<query name="find-all-by-slb-ids" type="SELECT" multiple="true">
|
||||
<param name="ids"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
WHERE <FIELD name='name'/> in <IN>${names}</IN>
|
||||
WHERE <FIELD name='slb-id'/> in <IN>${ids}</IN>
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
</query-defs>
|
||||
</entity>
|
||||
<entity name="conf-app-slb-active" table="conf_app_slb_active" alias="casa">
|
||||
<var name="names" value-type="String[]"/>
|
||||
<entity name="conf-group-slb-active" table="conf_group_slb_active" alias="cgsa">
|
||||
<var name="ids" value-type="Long[]"/>
|
||||
<query-defs>
|
||||
<query name="insert" type="INSERT">
|
||||
<statement>
|
||||
|
@ -73,29 +73,29 @@
|
|||
INSERT INTO <TABLE/>(<FIELDS/>)
|
||||
VALUES(<VALUES/>)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
app_name = values(app_name),
|
||||
slb_name = values(slb_name),
|
||||
slb_virtual_server_name = values(slb_virtual_server_name),
|
||||
group_id = values(group_id),
|
||||
slb_id = values(slb_id),
|
||||
slb_virtual_server_id = values(slb_virtual_server_id),
|
||||
<FIELD name="data-change-last-time"/> = NOW()
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="find-by-slb-name" type="SELECT" multiple="true">
|
||||
<param name="slb-name"/>
|
||||
<query name="find-by-slb-id" type="SELECT" multiple="true">
|
||||
<param name="slb-id"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
SELECT <FIELDS/>
|
||||
FROM <TABLE/>
|
||||
WHERE <FIELD name='slb-name'/> = ${slb-name}
|
||||
WHERE <FIELD name='slb-id'/> = ${slb-id}
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
<query name="delete-by-app-name" type="DELETE">
|
||||
<param name="app-name"/>
|
||||
<query name="delete-by-group-id" type="DELETE">
|
||||
<param name="group-id"/>
|
||||
<statement>
|
||||
<![CDATA[
|
||||
DELETE FROM <TABLE/>
|
||||
WHERE <FIELD name='app-name'/> = ${app-name}
|
||||
WHERE <FIELD name='group-id'/> = ${group-id}
|
||||
]]>
|
||||
</statement>
|
||||
</query>
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
<element name="ip" value-type="String" />
|
||||
</entity>
|
||||
<entity name="archive">
|
||||
<element name="name" value-type="String" />
|
||||
<element name="id" value-type="int" />
|
||||
<element name="content" value-type="String" />
|
||||
<element name="version" value-type="int" />
|
||||
</entity>
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
</group>
|
||||
|
||||
<archive>
|
||||
<name>gateway</name>
|
||||
<id>1</id>
|
||||
<content>groupXmlString</content>
|
||||
<version>1</version>
|
||||
</archive>
|
||||
|
|
Loading…
Reference in a new issue