summaryrefslogtreecommitdiffstats
path: root/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorDeleteOperation.java
blob: 5ff0d4a143fe8d83e36d14622bfc6b823f3c7fbf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator.transaction;

import com.yahoo.path.Path;
import com.yahoo.vespa.curator.Curator;
import org.apache.curator.framework.api.transaction.CuratorTransaction;

/**
 * @author lulf
 * @author bratseth
 */
class CuratorDeleteOperation implements CuratorOperation {

    private final String path;
    private final boolean throwIfNotExist;

    CuratorDeleteOperation(String path, boolean throwIfNotExist) {
        this.path = path;
        this.throwIfNotExist = throwIfNotExist;
    }

    @Override
    public void check(Curator curator) {
        if ( throwIfNotExist && ! curator.exists(Path.fromString(path)) )
            throw new IllegalStateException("Cannot perform " + this + ": Path does not exist");
    }

    @Override
    public CuratorTransaction and(CuratorTransaction transaction) throws Exception {
        return transaction.delete().forPath(path).and();
    }

    @Override
    public String toString() {
        return "DELETE " + path;
    }

}