/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.raptor.backup;

import org.weakref.jmx.Managed;
import org.weakref.jmx.Nested;

import java.io.File;
import java.util.UUID;

import static java.util.Objects.requireNonNull;

public class ManagedBackupStore
        implements BackupStore
{
    private final BackupStore store;

    private final BackupOperationStats backupShard = new BackupOperationStats();
    private final BackupOperationStats restoreShard = new BackupOperationStats();
    private final BackupOperationStats deleteShard = new BackupOperationStats();
    private final BackupOperationStats shardExists = new BackupOperationStats();

    public ManagedBackupStore(BackupStore store)
    {
        this.store = requireNonNull(store, "store is null");
    }

    @Override
    public void backupShard(UUID uuid, File source)
    {
        backupShard.run(() -> store.backupShard(uuid, source));
    }

    @Override
    public void restoreShard(UUID uuid, File target)
    {
        restoreShard.run(() -> store.restoreShard(uuid, target));
    }

    @Override
    public boolean deleteShard(UUID uuid)
    {
        return deleteShard.run(() -> store.deleteShard(uuid));
    }

    @Override
    public boolean shardExists(UUID uuid)
    {
        return shardExists.run(() -> store.shardExists(uuid));
    }

    @Managed
    @Nested
    public BackupOperationStats getBackupShard()
    {
        return backupShard;
    }

    @Managed
    @Nested
    public BackupOperationStats getRestoreShard()
    {
        return restoreShard;
    }

    @Managed
    @Nested
    public BackupOperationStats getDeleteShard()
    {
        return deleteShard;
    }

    @Managed
    @Nested
    public BackupOperationStats getShardExists()
    {
        return shardExists;
    }
}

@@ -599,16 +599,46 @@
 ackup;%0A%0A
+import io.airlift.log.Logger;%0A
 import o
@@ -661,16 +661,16 @@
 anaged;%0A
-
 import o
@@ -888,16 +888,46 @@
 e store;
+%0A    private final Logger log;
 %0A%0A    pr
@@ -1362,16 +1362,65 @@
 null%22);%0A
+        this.log = Logger.get(store.getClass());%0A
     %7D%0A%0A 
@@ -1482,32 +1482,86 @@
 e source)%0A    %7B%0A
+        log.debug(%22Creating shard backup: %25s%22, uuid);%0A
         backupSh
@@ -1680,32 +1680,87 @@
 e target)%0A    %7B%0A
+        log.debug(%22Restoring shard backup: %25s%22, uuid);%0A
         restoreS
@@ -1864,38 +1864,92 @@
 hard(UUID uuid)%0A
-
     %7B%0A
+        log.debug(%22Deleting shard backup: %25s%22, uuid);%0A
         return d

Add logging for Raptor backup operations