2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.direct;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.onap.aaf.auth.dao.cass.LocateDAO;
28 import org.onap.aaf.auth.env.AuthzEnv;
29 import org.onap.aaf.auth.env.AuthzTrans;
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.cadi.CadiException;
32 import org.onap.aaf.cadi.client.Result;
33 import org.onap.aaf.cadi.register.Registrant;
34 import org.onap.aaf.cadi.register.RegistrationCreator;
36 import locate.v1_0.MgmtEndpoint;
37 import locate.v1_0.MgmtEndpoints;
39 public class DirectRegistrar implements Registrant<AuthzEnv> {
41 private LocateDAO ldao;
42 private List<LocateDAO.Data> ldd;
43 public DirectRegistrar(Access access, LocateDAO ldao, int port) throws CadiException {
45 ldd = new ArrayList<>();
46 RegistrationCreator rc = new RegistrationCreator(access);
47 MgmtEndpoints mes = rc.create(port);
48 for(MgmtEndpoint me : mes.getMgmtEndpoint()) {
53 private LocateDAO.Data convert(MgmtEndpoint me) {
54 LocateDAO.Data out = new LocateDAO.Data();
55 out.name=me.getName();
56 out.hostname=me.getHostname();
57 out.latitude=me.getLatitude();
58 out.longitude=me.getLongitude();
59 out.major=me.getMajor();
60 out.minor=me.getMinor();
62 out.patch=me.getPatch();
63 out.port=me.getPort();
64 out.protocol=me.getProtocol();
65 out.subprotocol(true).addAll(me.getSubprotocol());
66 // out.port_key = UUID.randomUUID();
72 public Result<Void> update(AuthzEnv env) {
73 AuthzTrans trans = env.newTransNoAvg();
74 StringBuilder sb = null;
75 for(LocateDAO.Data ld : ldd) {
76 org.onap.aaf.auth.layer.Result<Void> dr = ldao.update(trans, ld);
79 sb = new StringBuilder(dr.errorString());
82 sb.append(dr.errorString());
88 return Result.ok(200, null);
90 return Result.err(503, sb.toString());
95 * @see org.onap.aaf.auth.server.Registrant#cancel(org.onap.aaf.auth.env.test.AuthzEnv)
98 public Result<Void> cancel(AuthzEnv env) {
99 AuthzTrans trans = env.newTransNoAvg();
100 StringBuilder sb = null;
101 for(LocateDAO.Data ld : ldd) {
102 org.onap.aaf.auth.layer.Result<Void> dr = ldao.delete(trans, ld, false);
105 sb = new StringBuilder(dr.errorString());
108 sb.append(dr.errorString());
114 return Result.ok(200, null);
116 return Result.err(503, sb.toString());