aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller
AgeCommit message (Expand)AuthorFilesLines
2019-08-22Fix the ingestion of mixed resourceeeginux1-12/+11
2019-08-19Merge "Solve the vnfc_instance_group_customization_id insertion failure problem"Seshu Kumar M1-0/+1
2019-08-19Close input streams via try-with-resourcesk.kazak1-5/+3
2019-08-16Merge "Initial commit of validation framework to APIH"Steve Smokowski1-0/+1
2019-08-16Solve the vnfc_instance_group_customization_id insertion failure problemzm3301-0/+1
2019-08-15Initial commit of validation framework to APIHSmokowski, Steven1-0/+1
2019-08-15asdc controller treat distributionid as requestidBhatt, Prema2-0/+37
2019-08-13- Updated vnfc instance groups to use theMerkel, Jeff2-77/+135
2019-08-13Merge "Change variable name-comply with regex"Seshu Kumar M1-2/+2
2019-08-12Change variable name-comply with regexsindhu36721-3/+3
2019-08-12Change variable name-comply with regexsindhu36721-2/+2
2019-08-09Merge if stmts for code readabilitysindhu36721-4/+2
2019-08-08Replace collections.size with isEmpty for better performancesindhu36723-7/+7
2019-08-06- Updated cvnfc's to use the getEntity API.Merkel, Jeff1-63/+72
2019-07-30Merge "repair vfcInstanceGroup order"Seshu Kumar M2-16/+102
2019-07-29Merge "Upgrade springboot.version from 2.0.5 to 2.1.5."Steve Smokowski1-0/+2
2019-07-29repair vfcInstanceGroup orderzm3302-16/+102
2019-07-26Upgrade springboot.version from 2.0.5 to 2.1.5.Sangalang, Felix1-0/+2
2019-07-26Merge "Fix the License issue inside the sample csar"subhash kumar singh1-0/+0
2019-07-23- Converted NetworkResource to use the parserMerkel, Jeff2-40/+78
2019-07-19Fix the License issue inside the sample csarseshukm1-0/+0
2019-07-18Removing application-local.yaml filesRoy, Amresh1-95/+0
2019-07-12Fixing ASDCRestInterface for CSIT to simulate SDC req.highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*-
 * ============LICENSE_START=======================================================
 * ONAP CLAMP
 * ================================================================================
 * Copyright (C) 2018-2019 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.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 * Modifications copyright (c) 2018 Nokia
 * ===================================================================
 *
 */

package org.onap.clamp.clds.sdc.controller;

import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;

import java.util.Date;
import java.util.Map.Entry;
import java.util.concurrent.ThreadLocalRandom;

import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
import org.onap.clamp.clds.exception.policy.PolicyModelException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcDownloadException;
import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintArtifact;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.IDistributionStatusMessage;
import org.onap.sdc.api.consumer.INotificationCallback;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.impl.DistributionClientFactory;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.utils.DistributionActionResultEnum;
import org.onap.sdc.utils.DistributionStatusEnum;

/**
 * This class handles one sdc controller defined in the config.
 */
public class SdcSingleController {

    private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSingleController.class);
    private boolean isSdcClientAutoManaged = false;
    private CsarInstaller csarInstaller;
    private ClampProperties refProp;
    /**
     * The constant CONFIG_SDC_FOLDER.
     */
    public static final String CONFIG_SDC_FOLDER = "sdc.csarFolder";
    private int nbOfNotificationsOngoing = 0;
    private SdcSingleControllerStatus controllerStatus = SdcSingleControllerStatus.STOPPED;
    private SdcSingleControllerConfiguration sdcConfig;
    private IDistributionClient distributionClient;

    /**
     * Inner class for Notification callback.
     */
    private final class SdcNotificationCallBack implements INotificationCallback {

        private SdcSingleController sdcController;

        /**
         * Instantiates a new Sdc notification call back.
         *
         * @param controller the controller
         */
        SdcNotificationCallBack(SdcSingleController controller) {
            sdcController = controller;
        }

        /**
         * This method can be called multiple times at the same moment. The controller
         * must be thread safe !
         */
        @Override
        public void activateCallback(INotificationData notificationData) {
            Date startTime = new Date();
            logger.info("Receive a callback notification in SDC, nb of resources: "
                    + notificationData.getResources().size());
            sdcController.treatNotification(notificationData);
            LoggingUtils.setTimeContext(startTime, new Date());
            LoggingUtils.setResponseContext("0", "SDC Notification received and processed successfully",
                    this.getClass().getName());
        }
    }

    /**
     * Gets nb of notifications ongoing.
     *
     * @return the nb of notifications ongoing
     */
    public int getNbOfNotificationsOngoing() {
        return nbOfNotificationsOngoing;
    }

    private void changeControllerStatusIdle() {
        if (this.nbOfNotificationsOngoing > 1) {
            --this.nbOfNotificationsOngoing;
        } else {
            this.nbOfNotificationsOngoing = 0;
            this.controllerStatus = SdcSingleControllerStatus.IDLE;
        }
    }

    /**
     * Change controller status.
     *
     * @param newControllerStatus the new controller status
     */
    protected final synchronized void changeControllerStatus(SdcSingleControllerStatus newControllerStatus) {
        switch