import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.UUID;
+import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.appc.CommonHeader;
import org.onap.policy.appc.Request;
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
+import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
-import org.onap.policy.controlloop.policy.PolicyResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public abstract class AppcOperation extends BidirectionalTopicOperation<Request, Response> {
private static final Logger logger = LoggerFactory.getLogger(AppcOperation.class);
- private static final StandardCoder coder = new StandardCoder();
+ private static final StandardCoder coder = new StandardCoderInstantAsMillis();
public static final String VNF_ID_KEY = "generic-vnf.vnf-id";
/**
*
* @param params operation parameters
* @param config configuration for this operation
+ * @param propertyNames names of properties required by this operation
*/
- public AppcOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
- super(params, config, Response.class);
+ public AppcOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config,
+ List<String> propertyNames) {
+ super(params, config, Response.class, propertyNames);
}
/**
* @param targetVnf target VNF
* @return a new request
*/
- protected Request makeRequest(int attempt, String targetVnf) {
+ protected Request makeRequest(int attempt, GenericVnf targetVnf) {
Request request = new Request();
request.setCommonHeader(new CommonHeader());
request.getCommonHeader().setRequestId(params.getRequestId());
-
- // TODO ok to use UUID, or does it have to be the "attempt"?
- request.getCommonHeader().setSubRequestId(UUID.randomUUID().toString());
+ request.getCommonHeader().setSubRequestId(getSubRequestId());
request.setAction(getName());
}
// add/replace specific values
- request.getPayload().put(VNF_ID_KEY, targetVnf);
+ request.getPayload().put(VNF_ID_KEY, targetVnf.getVnfId());
return request;
}
* @param source source from which to get the values
* @param target where to place the decoded values
*/
- private static void convertPayload(Map<String, String> source, Map<String, Object> target) {
- for (Entry<String, String> ent : source.entrySet()) {
+ private static void convertPayload(Map<String, Object> source, Map<String, Object> target) {
+ for (Entry<String, Object> ent : source.entrySet()) {
+ Object value = ent.getValue();
+ if (value == null) {
+ target.put(ent.getKey(), null);
+ continue;
+ }
+
try {
- target.put(ent.getKey(), coder.decode(ent.getValue(), Object.class));
+ target.put(ent.getKey(), coder.decode(value.toString(), Object.class));
} catch (CoderException e) {
logger.warn("cannot decode JSON value {}: {}", ent.getKey(), ent.getValue(), e);
*/
@Override
protected List<String> getExpectedKeyValues(int attempt, Request request) {
- return List.of(request.getCommonHeader().getSubRequestId());
+ return List.of(getSubRequestId());
}
@Override
protected Status detmStatus(String rawResponse, Response response) {
if (response.getStatus() == null) {
- throw new IllegalArgumentException("APP-C response is missing the response status");
+ // no status - this must be a request, not a response - just ignore it
+ logger.info("{}: ignoring request message for {}", getFullName(), params.getRequestId());
+ return Status.STILL_WAITING;
}
ResponseCode code = ResponseCode.toResponseCode(response.getStatus().getCode());
* Sets the message to the status description, if available.
*/
@Override
- public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, Response response) {
+ public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, Response response) {
+ outcome.setResponse(response);
+
if (response.getStatus() == null || response.getStatus().getDescription() == null) {
return setOutcome(outcome, result);
}
outcome.setMessage(response.getStatus().getDescription());
return outcome;
}
+
+ @Override
+ protected Coder getCoder() {
+ return coder;
+ }
}