dc3f13e8fb736934cc921e695e2953711f7fb48c
[aaf/authz.git] / authz-cass / src / test / java / com / att / dao / aaf / test / NS_ChildUpdate.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.dao.aaf.test;\r
25 \r
26 import com.att.authz.env.AuthzEnv;\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