blob: 31cdcb49042fa8c7969151a9ee383b67f5f2d01c [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cfm.cli;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070020import org.apache.karaf.shell.api.action.lifecycle.Service;
Sean Condon0e89bda2017-03-21 14:23:19 +000021import org.onosproject.cli.AbstractShellCommand;
Sean Condon0e89bda2017-03-21 14:23:19 +000022import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MaIdShort;
23import org.onosproject.incubator.net.l2monitoring.cfm.identifier.MdId;
Sean Condon0e89bda2017-03-21 14:23:19 +000024import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
25import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
26
27/**
28 * Delete a Maintenance Association from the existing list of a Maintenance Domain.
29 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070030@Service
Sean Condon0e89bda2017-03-21 14:23:19 +000031@Command(scope = "onos", name = "cfm-ma-delete",
32 description = "Delete a CFM Maintenance Association and its children.")
33public class CfmMaDeleteCommand extends AbstractShellCommand {
34
Sean Condon3a1efef2018-02-24 13:16:03 +000035 private static final int MA_NAME_PARTS_COUNT = 4;
36 @Argument(name = "name",
Sean Condon0e89bda2017-03-21 14:23:19 +000037 description = "Maintenance Domain name and type (in brackets) " +
38 "and the Maintenance Association name and type (in brackets)",
Sean Condon3a1efef2018-02-24 13:16:03 +000039 required = true)
40 private String name = null;
Sean Condon0e89bda2017-03-21 14:23:19 +000041
42 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070043 protected void doExecute() {
Sean Condon0e89bda2017-03-21 14:23:19 +000044 CfmMdService service = get(CfmMdService.class);
45
46 String[] nameParts = name.split("[()]");
Sean Condon3a1efef2018-02-24 13:16:03 +000047 if (nameParts.length != MA_NAME_PARTS_COUNT) {
Sean Condon0e89bda2017-03-21 14:23:19 +000048 throw new IllegalArgumentException("Invalid name format. Must be in " +
49 "the format of <identifier(name-type)identifier(name-type)>");
50 }
51
Sean Condon3a1efef2018-02-24 13:16:03 +000052 MdId mdId = CfmMdListMdCommand.parseMdName(nameParts[0] + "(" + nameParts[1] + ")");
Sean Condon0e89bda2017-03-21 14:23:19 +000053
Sean Condon3a1efef2018-02-24 13:16:03 +000054 MaIdShort maId = CfmMdListMdCommand.parseMaName(nameParts[2] + "(" + nameParts[3] + ")");
Sean Condon0e89bda2017-03-21 14:23:19 +000055
56 try {
57 boolean deleted = service.deleteMaintenanceAssociation(mdId, maId);
58 print("Maintenance Association %s-%s is %ssuccessfully deleted.",
59 mdId, maId, deleted ? "" : "NOT ");
60 } catch (CfmConfigException e) {
61 throw new IllegalArgumentException(e);
62 }
63 }
64}