Setting up new serviceutils features
[serviceutils.git] / srm / impl / src / main / java / org / opendaylight / serviceutils / srm / impl / ServiceRecoveryListener.java
1 /*
2  * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.serviceutils.srm.impl;
10
11 import javax.annotation.Nonnull;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.serviceutils.tools.mdsal.listener.AbstractClusteredSyncDataTreeChangeListener;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev170711.ServiceOps;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev170711.service.ops.Services;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev170711.service.ops.services.Operations;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 @Singleton
26 public class ServiceRecoveryListener extends AbstractClusteredSyncDataTreeChangeListener<Operations> {
27
28     private static final Logger LOG = LoggerFactory.getLogger(ServiceRecoveryListener.class);
29
30     private final ServiceRecoveryManager serviceRecoveryManager;
31
32     @Inject
33     public ServiceRecoveryListener(DataBroker dataBroker, ServiceRecoveryManager serviceRecoveryManager) {
34         super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(ServiceOps.class)
35                 .child(Services.class).child(Operations.class));
36         this.serviceRecoveryManager = serviceRecoveryManager;
37     }
38
39     @Override
40     public void add(@Nonnull InstanceIdentifier<Operations> instanceIdentifier, @Nonnull Operations operations) {
41         LOG.info("Service Recovery operation triggered for service: {}", operations);
42         serviceRecoveryManager.recoverService(operations.getEntityType(), operations.getEntityName(),
43                 operations.getEntityId());
44     }
45
46     @Override
47     public void remove(@Nonnull InstanceIdentifier<Operations> instanceIdentifier,
48                        @Nonnull Operations removedDataObject) {
49     }
50
51     @Override
52     public void update(@Nonnull InstanceIdentifier<Operations> instanceIdentifier,
53                        @Nonnull Operations originalDataObject, @Nonnull Operations updatedDataObject) {
54         add(instanceIdentifier, updatedDataObject);
55     }
56 }