Jian Li | 7b8c368 | 2019-05-12 13:57:15 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstacknetworking.impl; |
| 17 | |
| 18 | import org.onlab.packet.IpAddress; |
| 19 | import org.onosproject.core.CoreService; |
| 20 | import org.onosproject.openstacknetworking.api.Constants; |
| 21 | import org.onosproject.openstacknetworking.api.OpenstackHaService; |
| 22 | import org.osgi.service.component.annotations.Activate; |
| 23 | import org.osgi.service.component.annotations.Component; |
| 24 | import org.osgi.service.component.annotations.Deactivate; |
| 25 | import org.osgi.service.component.annotations.Reference; |
| 26 | import org.osgi.service.component.annotations.ReferenceCardinality; |
| 27 | import org.slf4j.Logger; |
| 28 | |
Daniel Park | c717c0f | 2019-09-15 16:38:06 +0900 | [diff] [blame] | 29 | import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_ACTIVE_IP_ADDRESS; |
| 30 | import static org.onosproject.openstacknetworking.api.Constants.DEFAULT_HA_STATUS; |
Jian Li | 7b8c368 | 2019-05-12 13:57:15 +0900 | [diff] [blame] | 31 | import 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 | ) |
| 40 | public class OpenstackHaManager implements OpenstackHaService { |
| 41 | |
| 42 | protected final Logger log = getLogger(getClass()); |
| 43 | |
Jian Li | 7b8c368 | 2019-05-12 13:57:15 +0900 | [diff] [blame] | 44 | @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 Park | c717c0f | 2019-09-15 16:38:06 +0900 | [diff] [blame] | 53 | activeFlag = DEFAULT_HA_STATUS; |
Jian Li | 7b8c368 | 2019-05-12 13:57:15 +0900 | [diff] [blame] | 54 | 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 | } |