blob: c5be52394228f731f2d40ec1afe7f0e919d9a41d [file] [log] [blame]
Jian Li7b8c3682019-05-12 13:57:15 +09001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.openstacknetworking.impl;
17
18import org.onlab.packet.IpAddress;
19import org.onosproject.core.CoreService;
20import org.onosproject.openstacknetworking.api.Constants;
21import org.onosproject.openstacknetworking.api.OpenstackHaService;
22import org.osgi.service.component.annotations.Activate;
23import org.osgi.service.component.annotations.Component;
24import org.osgi.service.component.annotations.Deactivate;
25import org.osgi.service.component.annotations.Reference;
26import org.osgi.service.component.annotations.ReferenceCardinality;
27import org.slf4j.Logger;
28
Daniel Parkc717c0f2019-09-15 16:38:06 +090029import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS;
30import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_HA_STATUS;
Jian Li7b8c3682019-05-12 13:57:15 +090031import static org.slf4j.LoggerFactory.getLogger;
32
33/**
34 * Provides implementation of administering and interfacing openstack HA service.
35 */
36@Component(
37 immediate = true,
38 service = { OpenstackHaService.class }
39)
40public class OpenstackHaManager implements OpenstackHaService {
41
42 protected final Logger log = getLogger(getClass());
43
Jian Li7b8c3682019-05-12 13:57:15 +090044 @Reference(cardinality = ReferenceCardinality.MANDATORY)
45 protected CoreService coreService;
46
47 boolean activeFlag;
48 IpAddress activeIpAddress;
49
50 @Activate
51 protected void activate() {
52 coreService.registerApplication(Constants.OPENSTACK_NETWORKING_APP_ID);
Daniel Parkc717c0f2019-09-15 16:38:06 +090053 activeFlag = DEFAULT_HA_STATUS;
Jian Li7b8c3682019-05-12 13:57:15 +090054 activeIpAddress = DEFAULT_ACTIVE_IP_ADDRESS;
55 log.info("Started");
56 }
57
58 @Deactivate
59 protected void deactivate() {
60 log.info("Stopped");
61 }
62
63 @Override
64 public boolean isActive() {
65 return activeFlag;
66 }
67
68 @Override
69 public IpAddress getActiveIp() {
70 return activeIpAddress;
71 }
72
73 @Override
74 public void setActiveIp(IpAddress ip) {
75 this.activeIpAddress = ip;
76 }
77
78 @Override
79 public void setActive(boolean flag) {
80 this.activeFlag = flag;
81 }
82}