first commit
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/common-smartgears-utils@92955 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c6a36c6dca
commit
d22ab4b6a7
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>common-smartgears-utils</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,35 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears-utils</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources.discovery</groupId>
|
||||
<artifactId>ic-client</artifactId>
|
||||
<version>1.0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>1.2.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,125 @@
|
|||
package org.gcube.smartgears.utils.sweeper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.ScopeGroup;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.informationsystem.publisher.AdvancedPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Andrea Manzi(CERN)
|
||||
*
|
||||
* Implements the sweeping on the IS in case a container state is cleaned
|
||||
*
|
||||
*/
|
||||
public class Sweeper {
|
||||
|
||||
String ghn_state_path = "";
|
||||
|
||||
Logger logger;
|
||||
|
||||
|
||||
public Sweeper () throws Exception {
|
||||
|
||||
logger = LoggerFactory.getLogger(Sweeper.class);
|
||||
|
||||
String ghn_path = System.getenv("GHN_HOME");
|
||||
|
||||
if (ghn_path == null ) {
|
||||
logger.error("GHN_HOME not defined");
|
||||
throw new Exception ("GHN_HOME not defined");
|
||||
}
|
||||
|
||||
ghn_state_path=ghn_path+File.separator+"state";
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public HostingNode getGHNProfile() throws JAXBException, FileNotFoundException {
|
||||
|
||||
JAXBContext jc = JAXBContext.newInstance(HostingNode.class);
|
||||
|
||||
Unmarshaller um = jc.createUnmarshaller();
|
||||
|
||||
HostingNode hostingNode = (HostingNode)
|
||||
um.unmarshal(new java.io.FileInputStream(ghn_state_path+File.separator+"ghn.xml" ));
|
||||
|
||||
return hostingNode;
|
||||
}
|
||||
|
||||
public ArrayList<GCoreEndpoint> getRunningInstanceProfiles() throws JAXBException {
|
||||
|
||||
ArrayList<GCoreEndpoint> endpoints = new ArrayList<GCoreEndpoint>();
|
||||
|
||||
JAXBContext jc = JAXBContext.newInstance(GCoreEndpoint.class);
|
||||
|
||||
Unmarshaller um = jc.createUnmarshaller();
|
||||
|
||||
File file = new File(ghn_state_path);
|
||||
|
||||
String[] files = file.list();
|
||||
|
||||
for (String name : files){
|
||||
File subfolder = new File(ghn_state_path+ File.separator+ name);
|
||||
if (subfolder.isDirectory()) {
|
||||
GCoreEndpoint ri;
|
||||
try {
|
||||
ri = (GCoreEndpoint)
|
||||
um.unmarshal(new java.io.FileInputStream(subfolder.getAbsolutePath()+File.separator+"endpoint.xml" ));
|
||||
} catch (FileNotFoundException | JAXBException e) {
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
endpoints.add(ri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
|
||||
public void cleanGHNProfile() throws FileNotFoundException, JAXBException{
|
||||
forceDeleteResource(this.getGHNProfile());
|
||||
|
||||
}
|
||||
|
||||
public void cleanRIProfiles() throws FileNotFoundException, JAXBException{
|
||||
for (GCoreEndpoint endp : this.getRunningInstanceProfiles()){
|
||||
forceDeleteResource(endp);
|
||||
}
|
||||
}
|
||||
|
||||
private void forceDeleteResource(Resource resource){
|
||||
|
||||
ScopeGroup<String> gr = resource.scopes();
|
||||
Iterator<String> it = gr.iterator();
|
||||
RegistryPublisher rp;
|
||||
AdvancedPublisher advancedPublisher;
|
||||
|
||||
while (it.hasNext()){
|
||||
String scope = it.next();
|
||||
ScopeProvider.instance.set(scope);
|
||||
rp=RegistryPublisherFactory.create();
|
||||
advancedPublisher=new AdvancedPublisher(rp);
|
||||
advancedPublisher.forceRemove(resource);
|
||||
logger.debug("Removing resource " + resource.id() + " from scope " + scope);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
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 SweeperClient {
|
||||
|
||||
public static void main (String args[]) {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(SweeperClient.class);
|
||||
|
||||
Sweeper sw = null;
|
||||
try {
|
||||
sw = new Sweeper();
|
||||
} catch (Exception e) {
|
||||
logger.error("Error initializing the Sweeper ", e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
sw.cleanGHNProfile();
|
||||
} catch (FileNotFoundException | JAXBException e) {
|
||||
logger.error("Error cleaning the GHN profile ", e);
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
sw.cleanRIProfiles();
|
||||
} catch (FileNotFoundException | JAXBException e) {
|
||||
logger.error("Error cleaning the RunningInstance profile ", e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
# Set root category priority to WARN and its only appender to A1.
|
||||
log4j.rootCategory=DEBUG, A0
|
||||
|
||||
log4j.appender.A0=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A0.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A0.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
|
||||
|
||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=[DT] %d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
|
||||
log4j.category.org.gcube=DEBUG,A1
|
||||
log4j.additivity.org.gcube=false
|
|
@ -0,0 +1,73 @@
|
|||
package org.gcube.smartgears.utils.sweeper.test;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.HostingNode;
|
||||
import org.gcube.smartgears.utils.sweeper.Sweeper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SweeperTest {
|
||||
|
||||
Sweeper sw = null;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
try {
|
||||
sw = new Sweeper();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getGHNProfile() {
|
||||
|
||||
HostingNode node = null;
|
||||
|
||||
try {
|
||||
node = sw.getGHNProfile();
|
||||
} catch (FileNotFoundException | JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Assert.assertNotNull(node);
|
||||
System.out.println(node.id());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRunningInstanceProfiles() {
|
||||
ArrayList<GCoreEndpoint> list = new ArrayList<GCoreEndpoint> ();
|
||||
try {
|
||||
list =sw.getRunningInstanceProfiles();
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("Endooint size :"+ list.size());
|
||||
for (GCoreEndpoint end : list){
|
||||
Assert.assertNotNull(end);
|
||||
System.out.println(end.id());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeGHNProfile() {
|
||||
|
||||
try {
|
||||
sw.cleanGHNProfile();
|
||||
} catch (FileNotFoundException | JAXBException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
# Set root category priority to WARN and its only appender to A1.
|
||||
log4j.rootCategory=DEBUG, A0
|
||||
|
||||
log4j.appender.A0=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A0.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A0.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
|
||||
|
||||
log4j.appender.A1=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A1.layout.ConversionPattern=[DT] %d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
|
||||
log4j.category.org.gcube=DEBUG,A1
|
||||
log4j.additivity.org.gcube=false
|
||||
|
||||
log4j.appender.A2=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.A2.layout.ConversionPattern=[TEST] %d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
|
||||
log4j.category.test=DEBUG,A2
|
||||
log4j.additivity.test=false
|
Loading…
Reference in New Issue