-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15368 from cdapio/operation-interface
CDAP-20809 Add LongRunningOperation interface
- Loading branch information
Showing
22 changed files
with
372 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/sourcecontrol/PullAppsOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* 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 io.cdap.cdap.internal.app.sourcecontrol; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.cdap.cdap.internal.operation.LongRunningOperation; | ||
import io.cdap.cdap.internal.operation.LongRunningOperationContext; | ||
import io.cdap.cdap.proto.operation.OperationError; | ||
|
||
/** | ||
* Defines operation for doing SCM Pull for connected repositories. | ||
* TODO(samik) implement the pull-op | ||
**/ | ||
public class PullAppsOperation implements LongRunningOperation { | ||
|
||
private final PullAppsRequest request; | ||
|
||
public PullAppsOperation(PullAppsRequest request) { | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public ListenableFuture<OperationError> run(LongRunningOperationContext context) { | ||
return null; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
cdap-app-fabric/src/main/java/io/cdap/cdap/internal/app/sourcecontrol/PullAppsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* 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 io.cdap.cdap.internal.app.sourcecontrol; | ||
|
||
import com.google.common.base.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* Request type for {@link PullAppsOperation}. | ||
*/ | ||
public class PullAppsRequest { | ||
|
||
private final Set<String> apps; | ||
|
||
/** | ||
* Default Constructor. | ||
* | ||
* @param apps Set of apps to pull. | ||
*/ | ||
public PullAppsRequest(Set<String> apps) { | ||
this.apps = apps; | ||
} | ||
|
||
public Set<String> getApps() { | ||
return apps; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
|
||
PullAppsRequest that = (PullAppsRequest) o; | ||
return Objects.equal(this.getApps(), that.getApps()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(getApps()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ic/src/main/java/io/cdap/cdap/internal/operation/AbstractLongRunningOperationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* 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 io.cdap.cdap.internal.operation; | ||
|
||
import io.cdap.cdap.proto.id.OperationRunId; | ||
import io.cdap.cdap.proto.operation.OperationType; | ||
|
||
/** | ||
* Abstract implementation of {@link LongRunningOperationContext} providing shared functionalities. | ||
*/ | ||
public abstract class AbstractLongRunningOperationContext implements LongRunningOperationContext { | ||
|
||
private final OperationRunId runId; | ||
private final OperationType type; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
protected AbstractLongRunningOperationContext(OperationRunId runid, OperationType operationType) { | ||
this.runId = runid; | ||
this.type = operationType; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
cdap-app-fabric/src/main/java/io/cdap/cdap/internal/operation/LongRunningOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* 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 io.cdap.cdap.internal.operation; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import io.cdap.cdap.proto.operation.OperationError; | ||
|
||
/** | ||
* LongRunningOperation represents a long-running asynchronous operation. | ||
*/ | ||
public interface LongRunningOperation { | ||
|
||
/** | ||
* Run the operation with the given request. | ||
* | ||
* @param request the operation input | ||
* @param updateMetadata func to update the metadata of the operation. This would be passed by | ||
* the runner. | ||
* @return {@link ListenableFuture} containing the {@link OperationError} for the run | ||
*/ | ||
ListenableFuture<OperationError> run(LongRunningOperationContext context); | ||
} |
53 changes: 53 additions & 0 deletions
53
...app-fabric/src/main/java/io/cdap/cdap/internal/operation/LongRunningOperationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright © 2023 Cask Data, Inc. | ||
* | ||
* 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 io.cdap.cdap.internal.operation; | ||
|
||
import io.cdap.cdap.proto.id.OperationRunId; | ||
import io.cdap.cdap.proto.operation.OperationResource; | ||
import io.cdap.cdap.proto.operation.OperationType; | ||
import java.util.Set; | ||
|
||
/** | ||
* Provides the context for the current operation run. | ||
*/ | ||
public interface LongRunningOperationContext { | ||
|
||
/** | ||
* Get the {@link OperationRunId} for the current run. | ||
* | ||
* @return the current runid | ||
*/ | ||
OperationRunId getRunId(); | ||
|
||
/** | ||
* Get the {@link OperationType} to be used by the runner for loading the right operation class. | ||
* | ||
* @return the type of the current operation | ||
*/ | ||
OperationType getType(); | ||
|
||
/** | ||
* Used by the {@link LongRunningOperation} to update the resources operated on in the | ||
* {@link io.cdap.cdap.proto.operation.OperationMeta} for the run. The input is set as we want all | ||
* resources to be unique | ||
* | ||
* @param resources A set of resources to be updated. | ||
* | ||
*/ | ||
// TODO Add exceptions based on implementations. | ||
void updateOperationResources(Set<OperationResource> resources); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.