aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>2020-09-25 14:29:31 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-25 14:29:31 +0000
commitf6531a05c76ec16b328d53866b954546e7be3aef (patch)
treeb4e254ea800fc9d29f03889b4cfd25479aa5a53a
parent9a34876ac4f5e2d0d0e4cfe3b46d29233d1c9956 (diff)
parentf9d12eb79014065b154920b4aa5731e71f2f8bfc (diff)
Merge "[SO] Fix typo"
-rwxr-xr-xkubernetes/so/charts/so-vnfm-adapter/templates/deployment.yaml2
1 files changed, 1 insertions, 1 deletions
diff --git a/kubernetes/so/charts/so-vnfm-adapter/templates/deployment.yaml b/kubernetes/so/charts/so-vnfm-adapter/templates/deployment.yaml
index 2dbfa4ea4a..ee84d60905 100755
--- a/kubernetes/so/charts/so-vnfm-adapter/templates/deployment.yaml
+++ b/kubernetes/so/charts/so-vnfm-adapter/templates/deployment.yaml
@@ -72,7 +72,7 @@ spec:
readOnly: true
- name: {{ include "common.fullname" . }}-truststore
mountPath: /app/client
- readonly: true
+ readOnly: true
livenessProbe:
tcpSocket:
port: {{ index .Values.livenessProbe.port }}
143' href='#n143'>143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
/*
 * Copyright 2017 Huawei Technologies Co., Ltd.
 *
 * 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.
 */

package org.onap.cli.fw;

import org.onap.cli.fw.ad.OnapAuthClient;
import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.conf.Constants;
import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandInvalidParameterType;
import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
import org.onap.cli.fw.error.OnapCommandNotInitialized;
import org.onap.cli.fw.error.OnapCommandParameterMissing;
import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.output.ResultType;
import org.onap.cli.fw.utils.OnapCommandUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Onap Command.
 *
 */
public abstract class OnapCommand {

    private String cmdDescription;

    private String cmdName;

    private String cmdSchemaName;

    private OnapService onapService = new OnapService();

    private List<OnapCommandParameter> cmdParameters = new ArrayList<>();

    private OnapCommandResult cmdResult = new OnapCommandResult();

    protected OnapAuthClient authClient;

    protected boolean isInitialzied = false;

    public String getSchemaVersion() {
        return Constants.ONAP_CMD_SCHEMA_VERSION_VALUE;
    }

    /**
     * Onap command description, defined by derived command.
     */
    public String getDescription() {
        return this.cmdDescription;
    }

    public void setDescription(String description) {
        this.cmdDescription = description;
    }

    /*
     * Onap command name like user-create, ns-list, etc , defined by derived command
     */
    public String getName() {
        return this.cmdName;
    }

    public void setName(String name) {
        this.cmdName = name;
    }

    public boolean isCommandInternal() {
        return onapService.getName() != null
                && onapService.getName().equalsIgnoreCase(OnapCommandConfg.getInternalCmd());
    }

    /*
     * Onap service, this command uses to execute it. , defined by derived command
     */
    public OnapService getService() {
        return this.onapService;
    }

    public void setService(OnapService service) {
        this.onapService = service;
    }

    public void setParameters(List<OnapCommandParameter> parameters) {
        this.cmdParameters = parameters;
    }

    /*
     * Onap command input parameters, defined by derived command
     */
    public List<OnapCommandParameter> getParameters() {
        return this.cmdParameters;
    }

    /*
     * Onap command input parameters, defined by derived command
     */
    public Map<String, OnapCommandParameter> getParametersMap() {
        return OnapCommandUtils.getInputMap(this.getParameters());
    }

    /*
     * Onap command output results, defined by derived command
     */
    public OnapCommandResult getResult() {
        return this.cmdResult;
    }

    public void setResult(OnapCommandResult result) {
        this.cmdResult = result;
    }

    public String getSchemaName() {
        return cmdSchemaName;
    }

    protected void setSchemaName(String schemaName) {
        this.cmdSchemaName = schemaName;
    }

    /**
     * Initialize this command from command schema.
     *
     * @throws OnapCommandRegistrationFailed
     *             Command Registration Exception
     * @throws OnapCommandInvalidResultAttributeScope
     *             InvalidResultAttribute Exception
     * @throws OnapCommandInvalidPrintDirection
     *             InvalidPrintDirection Exception
     * @throws OnapCommandInvalidParameterType
     *             InvalidParameterType Exception
     * @throws OnapCommandSchemaNotFound
     *             SchemaNotFound Exception
     * @throws OnapCommandInvalidSchema
     *             InvalidSchema Exception
     * @throws OnapCommandParameterOptionConflict
     *             ParameterOptionConflict Exception
     * @throws OnapCommandParameterNameConflict
     *             ParameterNameConflict Exception
     * @throws OnapCommandInvalidSchemaVersion
     *             InvalidSchemaVersion Exception
     */
    public void initializeSchema(String schema) throws OnapCommandException {
        this.setSchemaName(schema);
        OnapCommandUtils.loadSchema(this, schema, true);
        this.initializeProfileSchema();
        this.isInitialzied = true;
    }

    /**
     * Any additional profile based such as http/swagger schema could be initialized.
     */
    protected void initializeProfileSchema() throws OnapCommandException {
    }

    /*
     * Validate input parameters. This can be overridden in derived commands
     */
    protected void validate() throws OnapCommandException {
        for (OnapCommandParameter param : this.getParameters()) {
            try {
                param.validate();
            } catch (OnapCommandParameterMissing e) {
                if (OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd().contains(param.getName())) {
                    OnapCommandParameter noAuthParam = this.getParameters().stream().filter(p -> p.getName()
                            .equalsIgnoreCase(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH)).findFirst().get();

                    if ("true".equalsIgnoreCase(noAuthParam.getValue().toString())) {
                        continue;
                    }
                }
                throw e;
            } catch (OnapCommandException e) {
                throw e;
            }

        }
    }

    /**
     * Onap command execute with given parameters on service. Before calling this method, its mandatory to set all
     * parameters value.
     *
     * @throws OnapCommandException
     *             : General Command Exception
     */
    public OnapCommandResult execute() throws OnapCommandException {
        if (!this.isInitialzied) {
            throw new OnapCommandNotInitialized(this.getClass().getName());
        }

        Map<String, OnapCommandParameter> paramMap = this.getParametersMap();

        // -h or --help is always higher precedence !, user can set this value to get help message
        if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_HELP).getValue())) {
            OnapCommandResult result = new OnapCommandResult();
            result.setType(ResultType.TEXT);
            result.setOutput(this.printHelp());
            return result;
        }

        // -v or --version is next higher precedence !, user can set this value to get help message
        if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_VERSION).getValue())) {
            OnapCommandResult result = new OnapCommandResult();
            result.setType(ResultType.TEXT);
            result.setOutput(this.printVersion());
            return result;
        }

        // validate
        this.validate();

        // -f or --format
        this.cmdResult.setType(
                ResultType.get(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_FORMAT).getValue().toString()));
        if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_ATTR_LONG).getValue())) {
            this.cmdResult.setScope(OnapCommandResultAttributeScope.LONG);
        }
        // --no-title
        if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_TITLE).getValue())) {
            this.cmdResult.setIncludeTitle(false);
        }

        // --debug
        if ("true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_DEBUG).getValue())) {
            this.cmdResult.setDebug(true);
        }

        try {
            // login
            OnapCredentials creds = OnapCommandUtils.fromParameters(this.getParameters());
            boolean isAuthRequired = !this.onapService.isNoAuth()
                    && "true".equals(paramMap.get(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH).getValue());

            if (!isCommandInternal()) {
                this.authClient = new OnapAuthClient(creds, this.getResult().isDebug());
            }

            if (isAuthRequired) {
                this.authClient.login();
            }

            // execute
            this.run();

            // logout
            if (isAuthRequired) {
                this.authClient.logout();
            }

            if (this.cmdResult.isDebug() && authClient != null) {
                this.cmdResult.setDebugInfo(this.authClient.getDebugInfo());
            }
        } catch (OnapCommandException e) {
            if (this.cmdResult.isDebug() && authClient != null) {
                this.cmdResult.setDebugInfo(this.authClient.getDebugInfo());
            }
            throw e;
        }

        return this.cmdResult;
    }

    /*
     * Each command implements run method to executing the command.
     *
     */
    protected abstract void run() throws OnapCommandException;

    /*
     * Get my service base path (endpoint).
     */
    protected String getBasePath() throws OnapCommandException {
        return this.authClient.getServiceBasePath(this.getService());
    }

    protected String getAuthToken() {
        return this.authClient.getAuthToken();
    }

    /**
     * Returns the service service version it supports.
     *
     * @return version
     */
    public String printVersion() {
        return this.getService().toString();
    }

    /**
     * Provides help message for this command.
     *
     * @return help message
     * @throws OnapCommandHelpFailed
     *             Failed to execute Help command.
     */
    public String printHelp() throws OnapCommandHelpFailed {
        return OnapCommandUtils.help(this);
    }
    // (mrkanag) Add toString for all command, parameter, result, etc objects in JSON format
}