* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.att.research.xacml.api.Request;
import com.att.research.xacml.api.Response;
import com.att.research.xacml.util.XACMLPolicyScanner;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import lombok.NoArgsConstructor;
import org.apache.commons.io.IOUtils;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@NoArgsConstructor
public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(CoordinationGuardTranslator.class);
- public CoordinationGuardTranslator() {
- super();
- }
-
@Override
public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
LOGGER.debug("Using CoordinationGuardTranslator.convertPolicy");
// Policy name should be at the root
//
String type = toscaPolicy.getType();
- String coordinationFunctionPath = "src/main/resources/coordination/function";
+ var coordinationFunctionPath = "coordination/function";
Map<String, Object> policyProps = toscaPolicy.getProperties();
LOGGER.debug("path = {}", coordinationFunctionPath);
LOGGER.debug("props = {}", policyProps);
@SuppressWarnings("unchecked")
List<String> controlLoop = (List<String>) policyProps.get("controlLoop");
- CoordinationDirective cd = new CoordinationDirective();
+ var cd = new CoordinationDirective();
cd.setCoordinationFunction(type);
cd.setControlLoop(controlLoop);
LOGGER.debug("CoordinationDirective = {}", cd);
*/
public static CoordinationDirective loadCoordinationDirectiveFromFile(
String directiveFilename) {
+ if (directiveFilename == null) {
+ return null;
+ }
try (InputStream is = new FileInputStream(new File(directiveFilename))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
+ var contents = IOUtils.toString(is, StandardCharsets.UTF_8);
//
// Read the yaml into our Java Object
//
*/
String xacmlProtoFilename =
protoDir + File.separator + cd.getCoordinationFunction() + ".xml";
- LOGGER.debug("xacmlProtoFilename={}", xacmlProtoFilename);
+ LOGGER.info("xacmlProtoFilename={}", xacmlProtoFilename);
/*
- * Values to be used for placeholders
+ * Values to be substituted for placeholder's
*/
- final String uniqueId = UUID.randomUUID().toString();
+ final var uniqueId = UUID.randomUUID().toString();
final String cLOne = cd.getControlLoop(0);
final String cLTwo = cd.getControlLoop(1);
/*
- * Replace function placeholders with appropriate values
+ * Replace function placeholder's with appropriate values
*/
- String policyXml = ResourceUtils.getResourceAsString(xacmlProtoFilename);
+ var policyXml = ResourceUtils.getResourceAsString(xacmlProtoFilename);
if (policyXml == null) {
- throw new ToscaPolicyConversionException("Error while generating XACML policy for coordination directive");
+ throw new ToscaPolicyConversionException("Unable to find prototype " + xacmlProtoFilename);
}
policyXml = policyXml.replace("UNIQUE_ID", uniqueId);
policyXml = policyXml.replace("CONTROL_LOOP_ONE", cLOne);