import java.lang.reflect.Constructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
public interface ControlLoopLogger {
public void info(String... parameters);
public static class Factory {
- public ControlLoopLogger buildLogger(String className) {
+ private static final Logger logger = LoggerFactory.getLogger(Factory.class);
+
+
+ public ControlLoopLogger buildLogger(String className) throws ControlLoopException {
+
try {
Constructor<?> constr = Class.forName(className).getConstructor();
return (ControlLoopLogger) constr.newInstance();
} catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("Cannot load class " + className);
+ logger.error("buildLogger threw: ", e);
+ throw new ControlLoopException("Cannot load class " + className);
}
}
import java.lang.reflect.Constructor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public interface ControlLoopPublisher {
public void publish(Object object);
public static class Factory {
+ private static final Logger logger = LoggerFactory.getLogger(Factory.class);
- public ControlLoopPublisher buildLogger(String className) {
+
+ public ControlLoopPublisher buildLogger(String className) throws ControlLoopException {
try {
Constructor<?> constr = Class.forName(className).getConstructor();
return (ControlLoopPublisher) constr.newInstance();
} catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException("Cannot load class " + className);
+ logger.error("ControlLoopPublisher.buildLogger threw: ", e);
+ throw new ControlLoopException("Cannot load class " + className);
}
}
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.guard.PolicyGuard;
import org.onap.policy.guard.PolicyGuard.LockResult;
import org.onap.policy.guard.TargetLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ControlLoopEventManager implements LockCallback, Serializable {
/**
*
*/
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopEventManager.class);
+
private static final long serialVersionUID = -1216568161322872641L;
public final String closedLoopControlName;
public final UUID requestID;
private FinalResult controlLoopTimedOut = null;
private boolean isActivated = false;
- private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<ControlLoopOperation>();
+ private LinkedList<ControlLoopOperation> controlLoopHistory = new LinkedList<>();
private ControlLoopOperationManager currentOperation = null;
private TargetLock targetLock = null;
- private static Collection<String> requiredAAIKeys = new ArrayList<String>();
+ private static Collection<String> requiredAAIKeys = new ArrayList<>();
static {
requiredAAIKeys.add("AICVServerSelfLink");
requiredAAIKeys.add("AICIdentity");
//
this.isActivated = true;
} catch (ControlLoopException e) {
+ logger.error("{}: activate threw: ",this, e);
notification.notification = ControlLoopNotificationType.REJECTED;
notification.message = e.getMessage();
}
yamlSpecification = decodedYaml;
}
} catch (UnsupportedEncodingException e) {
+ logger.error("{}: activate threw: ",this, e);
}
//
// Parse the YAML specification
//
this.isActivated = true;
} catch (ControlLoopException e) {
+ logger.error("{}: activate threw: ",this, e);
notification.notification = ControlLoopNotificationType.REJECTED;
notification.message = e.getMessage();
}
return NEW_EVENT_STATUS.SYNTAX_ERROR;
}
} catch (ControlLoopException e) {
+ logger.error("{}: onNewEvent threw: ",this, e);
return NEW_EVENT_STATUS.SYNTAX_ERROR;
}
}
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
-
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ControlLoopOperationManager implements Serializable {
*
*/
private static final long serialVersionUID = -3773199283624595410L;
+ private static final Logger logger = LoggerFactory.getLogger(ControlLoopOperationManager.class);
@Override
public String toString() {
try{
em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager();//emf.createEntityManager();
}catch(Exception e){
- System.err.println("Test thread got Exception " + e.getLocalizedMessage() + " Can't write to Operations History DB.");
+ logger.error("storeOperationInDataBase threw: ", e);
return;
}
import com.att.research.xacml.api.DataTypeException;
import com.att.research.xacml.api.pdp.PDPEngine;
import com.att.research.xacml.std.annotations.RequestParser;
+
import java.util.UUID;
import org.drools.core.WorkingMemory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class CallGuardTask implements Runnable {
+ private static final Logger logger = LoggerFactory.getLogger(CallGuardTask.class);
WorkingMemory workingMemory;
PDPEngine embeddedPdpEngine;
String restfulPdpUrl;
try {
request = RequestParser.parseRequest(xacmlReq);
} catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("CallGuardTask.run threw: ", e);
}
import com.att.research.xacml.api.AttributeValue;
import com.att.research.xacml.api.Identifier;
import com.att.research.xacml.std.datatypes.DataTypes;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PIPEngineGetHistory extends StdConfigurableEngine{
- private Log logger = LogFactory.getLog(this.getClass());
+ private static final Logger logger = LoggerFactory.getLogger(PIPEngineGetHistory.class);
//private static EntityManager em;
public static final String DEFAULT_DESCRIPTION = "PIP for retrieving Operations History from DB";
try {
attributeValue = DataTypes.DT_INTEGER.createAttributeValue(value);
} catch (Exception ex) {
- this.logger.error("Failed to convert " + value + " to an AttributeValue<Boolean>", ex);
+ this.logger.error("Failed to convert {} to an AttributeValue<Boolean>",value, ex);
}
if (attributeValue != null) {
stdPIPResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, pipRequest.getIssuer()/*this.getIssuer()*/, false));
pipResponse = null;
}
} catch (PIPException ex) {
- System.out.println("PIPException getting subject-id attribute: " + ex.getMessage());
+ logger.error("getAttribute threw: ", ex);
}
return pipResponse;
}
try{
em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager();
}catch(Exception e){
- System.err.println("PIP thread got Exception " + e.getLocalizedMessage() + " Can't connect to Operations History DB.");
+ logger.error("getCountFromDB threw: ", e);
return -1;
}
- String sql = "select count(*) as count from operationshistory10 where outcome<>'Failure_Guard' and actor='"
- + actor
- + "' and operation='"
- + operation
- + "' and target='"
- + target
- + "' "
- + "and endtime between date_sub(now(),interval "
- + timeWindow
- + ") and now()";
-
- Query nq = em.createNativeQuery(sql);
+ String sql = "select count(*) as count from operationshistory10 where outcome<>'Failure_Guard'"
+ + " and actor=:actor"
+ + " and operation=:operation"
+ + " and target=:target"
+ + " and endtime between date_sub(now(),interval :timeWindow) and now()";
+
+ Query nq = em.createNativeQuery(sql);
+ nq = nq.setParameter("actor", actor);
+ nq = nq.setParameter("operation", operation);
+ nq = nq.setParameter("target", target);
+ nq = nq.setParameter("timeWindow", timeWindow);
int ret = -1;
try{
ret = ((Number)nq.getSingleResult()).intValue();
}
catch(NoResultException | NonUniqueResultException ex){
- System.err.println("PIP thread got Exception " + ex.getLocalizedMessage());
+ logger.error("getCountFromDB threw: ", ex);
return -1;
}
import org.apache.commons.io.IOUtils;
import org.apache.http.entity.ContentType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.att.research.xacml.api.Attribute;
import com.att.research.xacml.api.AttributeCategory;
public class PolicyGuardXacmlHelper {
-
+ private static final Logger logger = LoggerFactory.getLogger(PolicyGuardXacmlHelper.class);
public static com.att.research.xacml.api.Response callPDP(PDPEngine xacmlEmbeddedPdpEngine, String restfulPdpUrl, com.att.research.xacml.api.Request request, boolean isREST) {
//
contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) {
response = (com.att.research.xacml.api.Response) DOMResponse.load(connection.getInputStream());
} else {
- System.err.println("unknown content-type: " + contentType);
+ logger.error("{}: unknown content-type: ", contentType);
}
} catch (Exception e) {
String message = "Parsing Content-Type: " + connection.getContentType() + ", error=" + e.getMessage();
- System.err.println(message);
+ logger.error("{}: callRESTfulPDP threw: ", message);
}
} else {
- System.err.println(connection.getResponseCode() + " " + connection.getResponseMessage());
+ logger.error("unknown content-type: {} {}", connection.getResponseCode(), connection.getResponseMessage() );
}
} catch (Exception e) {
- System.err.println(e);
+
+ logger.error("callRESTfulPDP threw: ", e);
}
return response;
import java.util.regex.Pattern;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PolicyGuardYamlToXacml {
+ private static final Logger logger = LoggerFactory.getLogger(PolicyGuardYamlToXacml.class);
public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput){
Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes());
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("fromYamlToXacml threw: ", e);
}
}
Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes());
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("fromYamlToXacmlBlacklist threw: ", e);
}
}
import org.onap.policy.aai.util.Serialization;
import org.onap.policy.rest.RESTManager;
import org.onap.policy.rest.RESTManager.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.gson.JsonSyntaxException;
public final class AAINQF199Manager {
+ private static final Logger logger = LoggerFactory.getLogger(AAINQF199Manager.class);
public static AAINQF199Response postQuery(String url, String username, String password, AAINQF199Request request, UUID requestID) {
AAINQF199Response response = Serialization.gsonPretty.fromJson(httpDetails.b, AAINQF199Response.class);
return response;
} catch (JsonSyntaxException e) {
- System.err.println("Failed to deserialize into AAIResponse" + e.getLocalizedMessage());
+ logger.error("postQuery threw: ", e);
}
}
responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, AAIGETResponse.class);
return responseGet;
} catch (JsonSyntaxException e) {
- System.err.println("Failed to deserialize into AAIResponse" + e.getLocalizedMessage());
+ logger.error("getQuery threw: ", e);
}
}
try {
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
public final class Serialization {
- public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
+ public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
-
+ private static final Logger logger = LoggerFactory.getLogger(gsonUTCAdapter.class);
+
public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
throws JsonParseException {
try {
return ZonedDateTime.parse(element.getAsString(), format);
} catch (Exception e) {
- System.err.println(e);
+ logger.error("deserialize threw: ", e);
}
return null;
}
}
public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
- public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
+ public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
throws JsonParseException {
import org.onap.policy.mso.util.Serialization;
import org.onap.policy.rest.RESTManager;
import org.onap.policy.rest.RESTManager.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import com.google.gson.JsonSyntaxException;
public final class MSOManager {
+ private static final Logger logger = LoggerFactory.getLogger(MSOManager.class);
+
public static MSOResponse createModuleInstance(String url, String urlBase, String username, String password, MSORequest request) {
//
System.out.println("***** ######## VF Module Creation timeout. Status: ("+responseGet.request.requestStatus.requestState+")");
return responseGet;
} catch (JsonSyntaxException e) {
- System.err.println("Failed to deserialize into MSOResponse" + e.getLocalizedMessage());
+ logger.error("Failed to deserialize into MSOResponse: ", e);
} catch (InterruptedException e) {
- System.err.println("Interrupted exception: " + e.getLocalizedMessage());
+ logger.error("Interrupted exception: ", e);
}
}
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class RESTManager {
+ private static final Logger logger = LoggerFactory.getLogger(RESTManager.class);
+
public static class Pair<A, B> {
public final A a;
public final B b;
return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody);
} catch (IOException e) {
- System.err.println("Failed to POST to " + url + e.getLocalizedMessage());
+ logger.error("Failed to POST to {}",url,e);
+
return null;
}
return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody);
} catch (IOException e) {
- System.err.println("Failed to GET to " + url + e.getLocalizedMessage());
+ logger.error("Failed to GET to {}",url,e);
return null;
}
}
</plugin>
</plugins>
</reporting>
+ <dependencies>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.2.3</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
</project>