AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / authz-cmd / src / main / java / org / onap / aaf / cmd / mgmt / Log.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cmd.mgmt;\r
24 \r
25 import org.onap.aaf.authz.common.Define;\r
26 import org.onap.aaf.cmd.AAFcli;\r
27 import org.onap.aaf.cmd.BaseCmd;\r
28 import org.onap.aaf.cmd.Param;\r
29 import org.onap.aaf.cssa.rserv.HttpMethods;\r
30 \r
31 import org.onap.aaf.cadi.CadiException;\r
32 import org.onap.aaf.cadi.LocatorException;\r
33 import org.onap.aaf.cadi.client.Future;\r
34 import org.onap.aaf.cadi.client.Rcli;\r
35 import org.onap.aaf.cadi.client.Retryable;\r
36 import org.onap.aaf.inno.env.APIException;\r
37 \r
38 public class Log extends BaseCmd<Mgmt> {\r
39         private final static String[] options = {"add","del"};\r
40 \r
41         public Log(Mgmt mgmt) throws APIException {\r
42                 super(mgmt, "log",\r
43                                 new Param(optionsToString(options),true),\r
44                                 new Param("id[,id]*",true));\r
45         }\r
46         \r
47         @Override\r
48         public int _exec(int _idx, String ... args) throws CadiException, APIException, LocatorException {\r
49                 int rv=409;\r
50                 int idx = _idx;\r
51                 final int option = whichOption(options, args[idx++]);\r
52 \r
53                 for(String name : args[idx++].split(COMMA)) {\r
54                         final String fname;\r
55                         if(name.indexOf("@")<0) {\r
56                                 fname=name+'@'+ env.getProperty(AAFcli.AAF_DEFAULT_REALM);\r
57                         } else {\r
58                                 fname = name;\r
59                         }\r
60                         \r
61                         \r
62 \r
63                         rv = all(new Retryable<Integer>() {\r
64                                 @Override\r
65                                 public Integer code(Rcli<?> client) throws APIException, CadiException {\r
66                                         int rv = 409;\r
67                                         Future<Void> fp;\r
68                                         String str = "/mgmt/log/id/"+fname;\r
69                                         String msg;\r
70                                         switch(option) {\r
71                                                 case 0: \r
72                                                         fp = client.create(str,Void.class);\r
73                                                         msg = "Added";\r
74                                                         break;\r
75                                                 case 1:\r
76                                                         fp = client.delete(str,Void.class);\r
77                                                         msg = "Deleted";\r
78                                                         break;\r
79                                                 default:\r
80                                                         fp = null;\r
81                                                         msg = "Ignored";\r
82                                         }\r
83                                                         \r
84                                         if(fp!=null) {\r
85                                                 if(fp.get(AAFcli.timeout())) {\r
86                                                         pw().println(msg + " Special Log for " + fname + " on " + client);\r
87                                                         rv=200;\r
88                                                 } else {\r
89                                                         if(rv==409)rv = fp.code();\r
90                                                         error(fp);\r
91                                                 }\r
92                                                 return rv;\r
93                                         }\r
94                                         return rv;\r
95                                 }\r
96                         });\r
97                 }\r
98                 return rv;\r
99         }\r
100 \r
101         @Override\r
102         public void detailedHelp(int _indent, StringBuilder sb) {\r
103                 int indent = _indent;\r
104                 detailLine(sb,indent,"Clear the cache for certain tables");\r
105                 indent+=2;\r
106                 detailLine(sb,indent,"name        - name of table or 'all'");\r
107                 detailLine(sb,indent+14,"Must have admin rights to '" + Define.ROOT_NS + '\'');\r
108                 indent-=2;\r
109                 api(sb,indent,HttpMethods.DELETE,"mgmt/cache/:name",Void.class,true);\r
110         }\r
111 }\r