AT&T 2.0.19 Code drop, stage 4
[aaf/authz.git] / authz-cass / src / test / java / org / onap / aaf / dao / aaf / test / NS_ChildUpdate.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.dao.aaf.test;\r
24 \r
25 import org.onap.aaf.authz.env.AuthzEnv;\r
26 \r
27 import com.datastax.driver.core.Cluster;\r
28 import com.datastax.driver.core.ResultSet;\r
29 import com.datastax.driver.core.Row;\r
30 import com.datastax.driver.core.Session;\r
31 \r
32 public class NS_ChildUpdate {\r
33 \r
34         public static void main(String[] args) {\r
35                 if(args.length < 3 ) {\r
36                         System.out.println("usage: NS_ChildUpdate machine mechid (encrypted)passwd");\r
37                 } else {\r
38                         try {\r
39                                 AuthzEnv env = new AuthzEnv();\r
40                                 env.setLog4JNames("log.properties","authz","authz","audit","init","trace");\r
41                                 \r
42                                 Cluster cluster = Cluster.builder()\r
43                                                 .addContactPoint(args[0])\r
44                                                 .withCredentials(args[1],env.decrypt(args[2], false))\r
45                                                 .build();\r
46         \r
47                                 Session session = cluster.connect("authz");\r
48                                 try {\r
49                                         ResultSet result = session.execute("SELECT name,parent FROM ns");\r
50                                         int count = 0;\r
51                                         for(Row r : result.all()) {\r
52                                                 ++count;\r
53                                                 String name = r.getString(0);\r
54                                                 String parent = r.getString(1);\r
55                                                 if(parent==null) {\r
56                                                         int idx = name.lastIndexOf('.');\r
57                                                         \r
58                                                         parent = idx>0?name.substring(0, idx):".";\r
59                                                         System.out.println("UPDATE " + name + " to " + parent);\r
60                                                         session.execute("UPDATE ns SET parent='" + parent + "' WHERE name='" + name + "';");\r
61                                                 }\r
62                                         }\r
63                                         System.out.println("Processed " + count + " records");\r
64                                 } finally {\r
65                                         session.close();\r
66                                         cluster.close();\r
67                                 }\r
68                         } catch (Exception e) {\r
69                                 e.printStackTrace();\r
70                         }\r
71                 }\r
72         }\r
73 \r
74 }\r