This commit is contained in:
Lucio Lelii 2017-03-24 09:00:00 +00:00
parent e17e68c829
commit 46692d668a
9 changed files with 208 additions and 21 deletions

1
distro/LICENSE Normal file
View File

@ -0,0 +1 @@
${gcube.license}

59
distro/README Normal file
View File

@ -0,0 +1,59 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
Maintainers
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

11
distro/changelog.xml Normal file
View File

@ -0,0 +1,11 @@
<ReleaseNotes>
<Changeset component="common-smartgears-utils-1.0.3" date="2017-03-24">
<Change>refactoring for new state serialization model</Change>
</Changeset>
<Changeset component="common-smartgears-utils-1.0.2" date="2017-02-22">
<Change>Distro layout updated</Change>
</Changeset>
<Changeset component="common-smartgears-utils-1.0.0" date="2015-05-18">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

35
distro/descriptor.xml Normal file
View File

@ -0,0 +1,35 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

26
distro/profile.xml Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>Common</Class>
<Name>SmartgearsUtils</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-utils</artifactId>
<version>1.0.1-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>

View File

@ -24,16 +24,20 @@ public class ContainerSweeperClient {
logger.error("Error initializing the Sweeper ", e);
System.exit(1);
}
try {
if (args.length>0){
String savedTokenFileName = args[0];
sw.saveTokens(savedTokenFileName);
logger.info("file saved on Smartgears directory with name {} ",savedTokenFileName);
}
sw.forceDeleteHostingNode();
} catch (Exception e) {
logger.error("Error cleaning the GHN profile ", e);
System.exit(1);
}
}
}

View File

@ -0,0 +1,22 @@
package org.gcube.smartgears.utils.sweeper;
public class ContextBean {
private String token;
private String context;
public ContextBean(String token, String context) {
super();
this.token = token;
this.context = context;
}
public String getToken() {
return token;
}
public String getContext() {
return context;
}
}

View File

@ -4,7 +4,10 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.authorization.library.AuthorizationEntry;
@ -31,13 +34,17 @@ public class Sweeper {
String ghn_state_path = "";
Logger logger;
String ghn_path;
String id ;
List<ContextBean> contextBeans = new ArrayList<ContextBean>();
public Sweeper () throws Exception {
logger = LoggerFactory.getLogger(Sweeper.class);
String ghn_path = System.getenv("GHN_HOME");
ghn_path = System.getenv("GHN_HOME");
if (ghn_path == null ) {
logger.error("GHN_HOME not defined");
@ -46,32 +53,35 @@ public class Sweeper {
ghn_state_path=ghn_path+File.separator+"state";
deserializeState();
}
@SuppressWarnings("unchecked")
public void forceDeleteHostingNode(){
String id ;
List<String> tokens ;
private void deserializeState(){
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream(ghn_state_path+File.separator+"ghn.xml"))){
id = (String)ois.readObject();
tokens = (List<String>) ois.readObject();
List<String> tokens = (List<String>) ois.readObject();
for (String token : tokens){
AuthorizationEntry entry = authorizationService().get(token);
contextBeans.add(new ContextBean(token, entry.getContext()));
}
}catch(Exception e){
throw new RuntimeException("error loading persisted state");
}
}
public void forceDeleteHostingNode(){
RegistryPublisher rp=RegistryPublisherFactory.create();
System.out.println(" id to remove is "+id);
try{
DiscoveryClient<HostingNode> client = ICFactory.clientFor(HostingNode.class);
SimpleQuery query = ICFactory.queryFor(HostingNode.class);
query.addCondition("$resource/ID/text() = '"+id+"'");
for (String token : tokens){
AuthorizationEntry entry = authorizationService().get(token);
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(entry.getContext());
System.out.println("trying to remove resource in scope "+entry.getContext());
for (ContextBean contextBean : contextBeans){
SecurityTokenProvider.instance.set(contextBean.getToken());
ScopeProvider.instance.set(contextBean.getContext());
List<HostingNode> nodes = client.submit(query);
System.out.println(" node is empty? "+nodes.isEmpty());
if (nodes.isEmpty()) continue;
rp.remove(nodes.get(0));
}
@ -81,8 +91,27 @@ public class Sweeper {
throw new RuntimeException("error removing hosting node resource",e);
}
}
public void saveTokens(String fileName){
File file = new File(ghn_path+File.separator+fileName);
try {
if (file.exists())
file.delete();
file.createNewFile();
} catch (IOException e1) {
throw new RuntimeException(e1);
}
try(FileWriter fw = new FileWriter(file)){
for (ContextBean bean: contextBeans){
fw.write("<token>"+bean.getToken()+"</token> <!--- "+bean.getContext()+" -->\n");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}