Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-cass / src / test / java / com / att / dao / aaf / test / NS_ChildUpdate.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package com.att.dao.aaf.test;
23
24 import org.onap.aaf.auth.dao.CassAccess;
25 import org.onap.aaf.auth.env.AuthzEnv;
26
27 import com.datastax.driver.core.Cluster;
28 import com.datastax.driver.core.ResultSet;
29 import com.datastax.driver.core.Row;
30 import com.datastax.driver.core.Session;
31
32 public class NS_ChildUpdate {
33
34         public static void main(String[] args) {
35                 if(args.length < 3 ) {
36                         System.out.println("usage: NS_ChildUpdate machine mechid (encrypted)passwd");
37                 } else {
38                         try {
39                                 AuthzEnv env = new AuthzEnv();
40                                 env.setLog4JNames("log.properties","authz","authz","audit","init","trace");
41                                 
42                                 Cluster cluster = Cluster.builder()
43                                                 .addContactPoint(args[0])
44                                                 .withCredentials(args[1],env.decrypt(args[2], false))
45                                                 .build();
46         
47                                 Session session = cluster.connect(CassAccess.KEYSPACE);
48                                 try {
49                                         ResultSet result = session.execute("SELECT name,parent FROM ns");
50                                         int count = 0;
51                                         for(Row r : result.all()) {
52                                                 ++count;
53                                                 String name = r.getString(0);
54                                                 String parent = r.getString(1);
55                                                 if(parent==null) {
56                                                         int idx = name.lastIndexOf('.');
57                                                         
58                                                         parent = idx>0?name.substring(0, idx):".";
59                                                         System.out.println("UPDATE " + name + " to " + parent);
60                                                         session.execute("UPDATE ns SET parent='" + parent + "' WHERE name='" + name + "';");
61                                                 }
62                                         }
63                                         System.out.println("Processed " + count + " records");
64                                 } finally {
65                                         session.close();
66                                         cluster.close();
67                                 }
68                         } catch (Exception e) {
69                                 e.printStackTrace();
70                         }
71                 }
72         }
73
74 }