Skip to content

Commit

Permalink
Add ResourceModelSourceErrors to provide oob errors for ResourceModel…
Browse files Browse the repository at this point in the history
…Source
  • Loading branch information
gschueler committed Apr 27, 2016
1 parent 4215252 commit 2a9cc94
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.resources.*;
import com.dtolabs.rundeck.core.resources.format.*;
import com.dtolabs.rundeck.core.utils.TextUtils;
import org.apache.log4j.Logger;

import java.io.File;
Expand Down Expand Up @@ -94,7 +95,30 @@ public INodeSet getNodeSet() {
} else {
list.addNodeSet(nodes);
}
validSources.add(index + ".source");
boolean hasErrors=false;
if(nodesSource instanceof ResourceModelSourceErrors){
ResourceModelSourceErrors nodeerrors = (ResourceModelSourceErrors) nodesSource;
List<String> modelSourceErrors = nodeerrors.getModelSourceErrors();
if(modelSourceErrors!=null && modelSourceErrors.size()>0){
hasErrors=true;
logger.error("Some errors getting nodes from [" +
nodesSource.toString() +
"]: " +
modelSourceErrors);
exceptions.put(
index + ".source",
new ResourceModelSourceException(
TextUtils.join(
modelSourceErrors.toArray(new String[modelSourceErrors.size()]),
';'
)
)
);
}
}
if(!hasErrors) {
validSources.add(index + ".source");
}
} catch (ResourceModelSourceException | RuntimeException e) {
logger.error("Cannot get nodes from [" + nodesSource.toString() + "]: " + e.getMessage());
logger.debug("Cannot get nodes from [" + nodesSource.toString() + "]: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import com.dtolabs.rundeck.core.common.INodeSet;

import java.util.List;

/**
* Delegating source meant to be subclassed
*/
public abstract class DelegateResourceModelSource implements ResourceModelSource {
public abstract class DelegateResourceModelSource implements ResourceModelSource,ResourceModelSourceErrors {
private ResourceModelSource delegate;

public DelegateResourceModelSource(ResourceModelSource delegate) {
Expand All @@ -36,4 +38,13 @@ public INodeSet getNodes() throws ResourceModelSourceException {
public ResourceModelSource getDelegate() {
return delegate;
}

@Override
public List<String> getModelSourceErrors() {
if(getDelegate() instanceof ResourceModelSourceErrors){
return ((ResourceModelSourceErrors)getDelegate()).getModelSourceErrors();
}else{
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dtolabs.rundeck.core.resources;

import java.util.List;

/**
* Optional Extension to {@link ResourceModelSource} to provide out of band error messages, even if
* the source can provide some results.
*/
public interface ResourceModelSourceErrors {
List<String> getModelSourceErrors();
}

0 comments on commit 2a9cc94

Please sign in to comment.