separated ContainerSweeperClient and AppSweeperClient

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/common-smartgears-utils@93607 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
andrea.manzi 2014-03-27 05:57:43 +00:00
parent a459c4c9ef
commit 9dd9329ba1
4 changed files with 87 additions and 9 deletions

View File

@ -0,0 +1,46 @@
package org.gcube.smartgears.utils.sweeper;
import java.io.FileNotFoundException;
import javax.xml.bind.JAXBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author andrea
*
*/
public class AppSweeperClient {
public static void main (String args[]) {
Logger logger = LoggerFactory.getLogger(AppSweeperClient.class);
if (args.length <1) {
logger.error("Missing app name parameter");
System.exit(1);
}
String name = args[0];
Sweeper sw = null;
try {
sw = new Sweeper();
} catch (Exception e) {
logger.error("Error initializing the Sweeper ", e);
System.exit(1);
}
try {
sw.cleanRIProfile(name);
} catch (Exception e) {
logger.error("Error cleaning the RunningInstance profile ", e);
System.exit(1);
}
}
}

View File

@ -12,11 +12,12 @@ import org.slf4j.LoggerFactory;
* @author andrea
*
*/
public class SweeperClient {
public class ContainerSweeperClient {
public static void main (String args[]) {
Logger logger = LoggerFactory.getLogger(SweeperClient.class);
Logger logger = LoggerFactory.getLogger(ContainerSweeperClient.class);
Sweeper sw = null;
try {
@ -26,15 +27,17 @@ public class SweeperClient {
System.exit(1);
}
try {
sw.cleanGHNProfile();
} catch (FileNotFoundException | JAXBException e) {
} catch (Exception e) {
logger.error("Error cleaning the GHN profile ", e);
System.exit(1);
}
try {
sw.cleanRIProfiles();
} catch (FileNotFoundException | JAXBException e) {
} catch (Exception e) {
logger.error("Error cleaning the RunningInstance profiles ", e);
System.exit(1);
}

View File

@ -63,7 +63,31 @@ public class Sweeper {
return hostingNode;
}
public ArrayList<GCoreEndpoint> getRunningInstanceProfiles() throws JAXBException {
public GCoreEndpoint getRunningInstanceProfile(String name) throws Exception {
JAXBContext jc = JAXBContext.newInstance(GCoreEndpoint.class);
Unmarshaller um = jc.createUnmarshaller();
GCoreEndpoint ri = null;
File subfolder = new File(ghn_state_path+ File.separator+ name);
try {
ri = (GCoreEndpoint)
um.unmarshal(new java.io.FileInputStream(subfolder.getAbsolutePath()+File.separator+"endpoint.xml" ));
} catch (FileNotFoundException | JAXBException e) {
e.printStackTrace();
throw new Exception(e);
}
return ri;
}
public ArrayList<GCoreEndpoint> getRunningInstanceProfiles() throws Exception {
ArrayList<GCoreEndpoint> endpoints = new ArrayList<GCoreEndpoint>();
@ -95,12 +119,17 @@ public class Sweeper {
}
public void cleanGHNProfile() throws FileNotFoundException, JAXBException{
public void cleanGHNProfile() throws Exception{
forceDeleteResource(this.getGHNProfile());
}
public void cleanRIProfiles() throws FileNotFoundException, JAXBException{
public void cleanRIProfile(String name) throws Exception{
forceDeleteResource(this.getRunningInstanceProfile(name));
}
public void cleanRIProfiles() throws Exception{
for (GCoreEndpoint endp : this.getRunningInstanceProfiles()){
forceDeleteResource(endp);
}

View File

@ -48,7 +48,7 @@ public class SweeperTest {
ArrayList<GCoreEndpoint> list = new ArrayList<GCoreEndpoint> ();
try {
list =sw.getRunningInstanceProfiles();
} catch (JAXBException e) {
} catch (Exception e) {
e.printStackTrace();
}
@ -65,7 +65,7 @@ public class SweeperTest {
try {
sw.cleanGHNProfile();
} catch (FileNotFoundException | JAXBException e) {
} catch (Exception e) {
e.printStackTrace();
}