Search in sources :

Example 1 with CommonHeader

use of org.onap.appc.client.lcm.model.CommonHeader in project so by onap.

the class ApplicationControllerClient method createRequest.

public Object createRequest(Action action, ActionIdentifiers identifier, Payload payload, String requestId, String requestorId) {
    Object requestObject = appCSupport.getInput(action.name());
    try {
        CommonHeader commonHeader = buildCommonHeader(requestId, requestorId);
        requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject, commonHeader);
        requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action);
        requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class).invoke(requestObject, identifier);
        if (payload != null) {
            logger.info("payload in RunCommand: " + payload.getValue());
            requestObject.getClass().getDeclaredMethod("setPayload", Payload.class).invoke(requestObject, payload);
        }
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        logger.error("Error building Appc request", e);
    }
    return requestObject;
}
Also used : CommonHeader(org.onap.appc.client.lcm.model.CommonHeader) Action(org.onap.appc.client.lcm.model.Action) Payload(org.onap.appc.client.lcm.model.Payload) ActionIdentifiers(org.onap.appc.client.lcm.model.ActionIdentifiers) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with CommonHeader

use of org.onap.appc.client.lcm.model.CommonHeader in project so by onap.

the class ApplicationControllerClient method buildCommonHeader.

protected CommonHeader buildCommonHeader(String requestId, String requestorId) {
    CommonHeader commonHeader = new CommonHeader();
    commonHeader.setApiVer(API_VER);
    commonHeader.setOriginatorId(ORIGINATOR_ID);
    commonHeader.setRequestId(requestId == null ? UUID.randomUUID().toString() : requestId);
    commonHeader.setSubRequestId(UUID.randomUUID().toString());
    Flags flags = new Flags();
    String flagsMode = "NORMAL";
    Mode mode = Mode.valueOf(flagsMode);
    flags.setMode(mode);
    String flagsForce = "FALSE";
    Force force = Force.valueOf(flagsForce);
    flags.setForce(force);
    flags.setTtl(FLAGS_TTL);
    commonHeader.setFlags(flags);
    Instant timestamp = Instant.now();
    ZULU zulu = new ZULU(timestamp.toString());
    commonHeader.setTimestamp(zulu);
    return commonHeader;
}
Also used : CommonHeader(org.onap.appc.client.lcm.model.CommonHeader) Force(org.onap.appc.client.lcm.model.Flags.Force) Mode(org.onap.appc.client.lcm.model.Flags.Mode) Instant(java.time.Instant) Flags(org.onap.appc.client.lcm.model.Flags) ZULU(org.onap.appc.client.lcm.model.ZULU)

Example 3 with CommonHeader

use of org.onap.appc.client.lcm.model.CommonHeader in project so by onap.

the class ApplicationControllerClient method createRequest.

public Object createRequest(Action action, ActionIdentifiers identifier, Payload payload, String requestId) {
    Object requestObject = appCSupport.getInput(action.name());
    try {
        CommonHeader commonHeader = buildCommonHeader(requestId);
        requestObject.getClass().getDeclaredMethod("setCommonHeader", CommonHeader.class).invoke(requestObject, commonHeader);
        requestObject.getClass().getDeclaredMethod("setAction", Action.class).invoke(requestObject, action);
        requestObject.getClass().getDeclaredMethod("setActionIdentifiers", ActionIdentifiers.class).invoke(requestObject, identifier);
        if (payload != null) {
            requestObject.getClass().getDeclaredMethod("setPayload", Payload.class).invoke(requestObject, payload);
        }
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        logger.error("Error building Appc request", e);
    }
    return requestObject;
}
Also used : CommonHeader(org.onap.appc.client.lcm.model.CommonHeader) Action(org.onap.appc.client.lcm.model.Action) Payload(org.onap.appc.client.lcm.model.Payload) ActionIdentifiers(org.onap.appc.client.lcm.model.ActionIdentifiers) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with CommonHeader

use of org.onap.appc.client.lcm.model.CommonHeader in project so by onap.

the class ApplicationControllerClient method buildCommonHeader.

private CommonHeader buildCommonHeader(String requestId) {
    CommonHeader commonHeader = new CommonHeader();
    commonHeader.setApiVer(API_VER);
    commonHeader.setOriginatorId(ORIGINATOR_ID);
    commonHeader.setRequestId(requestId == null ? UUID.randomUUID().toString() : requestId);
    commonHeader.setSubRequestId(UUID.randomUUID().toString());
    Flags flags = new Flags();
    String flagsMode = "NORMAL";
    Mode mode = Mode.valueOf(flagsMode);
    flags.setMode(mode);
    String flagsForce = "FALSE";
    Force force = Force.valueOf(flagsForce);
    flags.setForce(force);
    flags.setTtl(FLAGS_TTL);
    commonHeader.setFlags(flags);
    ZULU zulu = new ZULU(generateCurrentTimestamp(this.controllerType));
    commonHeader.setTimestamp(zulu);
    return commonHeader;
}
Also used : CommonHeader(org.onap.appc.client.lcm.model.CommonHeader) Force(org.onap.appc.client.lcm.model.Flags.Force) Mode(org.onap.appc.client.lcm.model.Flags.Mode) Flags(org.onap.appc.client.lcm.model.Flags) ZULU(org.onap.appc.client.lcm.model.ZULU)

Aggregations

CommonHeader (org.onap.appc.client.lcm.model.CommonHeader)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Action (org.onap.appc.client.lcm.model.Action)2 ActionIdentifiers (org.onap.appc.client.lcm.model.ActionIdentifiers)2 Flags (org.onap.appc.client.lcm.model.Flags)2 Force (org.onap.appc.client.lcm.model.Flags.Force)2 Mode (org.onap.appc.client.lcm.model.Flags.Mode)2 Payload (org.onap.appc.client.lcm.model.Payload)2 ZULU (org.onap.appc.client.lcm.model.ZULU)2 Instant (java.time.Instant)1