|
|
|
@ -7,8 +7,11 @@ import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
@ -16,6 +19,7 @@ import org.gcube.common.resources.gcore.HostingNode;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
|
|
|
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
|
|
|
|
import org.gcube.informationsystem.publisher.ScopedPublisher;
|
|
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
|
|
|
import org.gcube.resources.discovery.icclient.ICFactory;
|
|
|
|
@ -38,13 +42,13 @@ public class Sweeper {
|
|
|
|
|
String ghn_path;
|
|
|
|
|
|
|
|
|
|
String id ;
|
|
|
|
|
List<ContextBean> contextBeans = new ArrayList<ContextBean>();
|
|
|
|
|
Set<ContextBean> contextBeans = new HashSet<ContextBean>();
|
|
|
|
|
|
|
|
|
|
public Sweeper () throws Exception {
|
|
|
|
|
public Sweeper (String ghnPath) throws Exception {
|
|
|
|
|
|
|
|
|
|
logger = LoggerFactory.getLogger(Sweeper.class);
|
|
|
|
|
|
|
|
|
|
ghn_path = System.getenv("GHN_HOME");
|
|
|
|
|
ghn_path = ghnPath;
|
|
|
|
|
|
|
|
|
|
if (ghn_path == null ) {
|
|
|
|
|
logger.error("GHN_HOME not defined");
|
|
|
|
@ -72,21 +76,27 @@ public class Sweeper {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void forceDeleteHostingNode(){
|
|
|
|
|
RegistryPublisher rp=RegistryPublisherFactory.create();
|
|
|
|
|
ScopedPublisher rp=RegistryPublisherFactory.scopedPublisher();
|
|
|
|
|
try{
|
|
|
|
|
DiscoveryClient<HostingNode> client = ICFactory.clientFor(HostingNode.class);
|
|
|
|
|
SimpleQuery query = ICFactory.queryFor(HostingNode.class);
|
|
|
|
|
query.addCondition("$resource/ID/text() = '"+id+"'");
|
|
|
|
|
List<String> scopes = contextBeans.stream().map(b -> b.getContext()).collect(Collectors.toList());
|
|
|
|
|
ScopeProvider.instance.set(scopes.get(0));
|
|
|
|
|
HostingNode node =null;
|
|
|
|
|
for (ContextBean contextBean : contextBeans){
|
|
|
|
|
|
|
|
|
|
SecurityTokenProvider.instance.set(contextBean.getToken());
|
|
|
|
|
ScopeProvider.instance.set(contextBean.getContext());
|
|
|
|
|
List<HostingNode> nodes = client.submit(query);
|
|
|
|
|
if (nodes.isEmpty()) continue;
|
|
|
|
|
rp.remove(nodes.get(0));
|
|
|
|
|
else {
|
|
|
|
|
node = nodes.get(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rp.remove(node, scopes);
|
|
|
|
|
ScopeProvider.instance.reset();
|
|
|
|
|
}catch(Exception e){
|
|
|
|
|
throw new RuntimeException("error removing hosting node resource",e);
|
|
|
|
|
}
|
|
|
|
|