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 | |
| 29 | import static org.slf4j.LoggerFactory.getLogger; |
| 30 | |
| 31 | /** |
| 32 | * Provides implementation of administering and interfacing openstack HA service. |
| 33 | */ |
| 34 | @Component( |
| 35 | immediate = true, |
| 36 | service = { OpenstackHaService.class } |
| 37 | ) |
| 38 | public class OpenstackHaManager implements OpenstackHaService { |
| 39 | |
| 40 | protected final Logger log = getLogger(getClass()); |
| 41 | |
| 42 | private static final boolean DEFAULT_ACTIVE_STATUS = true; |
| 43 | private static final IpAddress DEFAULT_ACTIVE_IP_ADDRESS = IpAddress.valueOf("127.0.0.1"); |
| 44 | |
| 45 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 46 | protected CoreService coreService; |
| 47 | |
| 48 | boolean activeFlag; |
| 49 | IpAddress activeIpAddress; |
| 50 | |
| 51 | @Activate |
| 52 | protected void activate() { |
| 53 | coreService.registerApplication(Constants.OPENSTACK_NETWORKING_APP_ID); |
| 54 | activeFlag = DEFAULT_ACTIVE_STATUS; |
| 55 | activeIpAddress = DEFAULT_ACTIVE_IP_ADDRESS; |
| 56 | log.info("Started"); |
| 57 | } |
| 58 | |
| 59 | @Deactivate |
| 60 | protected void deactivate() { |
| 61 | log.info("Stopped"); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public boolean isActive() { |
| 66 | return activeFlag; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public IpAddress getActiveIp() { |
| 71 | return activeIpAddress; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void setActiveIp(IpAddress ip) { |
| 76 | this.activeIpAddress = ip; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public void setActive(boolean flag) { |
| 81 | this.activeFlag = flag; |
| 82 | } |
| 83 | } |