| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.compute.config; |
| 20 | |
| 21 | import static com.google.common.base.Predicates.not; |
| 22 | |
| 23 | import javax.inject.Named; |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.compute.domain.NodeMetadata; |
| 27 | import org.jclouds.compute.predicates.NodeRunning; |
| 28 | import org.jclouds.compute.predicates.NodeSuspended; |
| 29 | import org.jclouds.compute.predicates.NodeTerminated; |
| 30 | import org.jclouds.compute.predicates.ScriptStatusReturnsZero; |
| 31 | import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; |
| 32 | import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; |
| 33 | import org.jclouds.predicates.RetryablePredicate; |
| 34 | |
| 35 | import com.google.common.base.Predicate; |
| 36 | import com.google.inject.AbstractModule; |
| 37 | import com.google.inject.Provides; |
| 38 | |
| 39 | /** |
| 40 | * |
| 41 | * @author Adrian Cole |
| 42 | * |
| 43 | */ |
| 44 | public class ComputeServiceTimeoutsModule extends AbstractModule { |
| 45 | |
| 46 | @Provides |
| 47 | @Singleton |
| 48 | @Named("NODE_RUNNING") |
| 49 | protected Predicate<NodeMetadata> nodeRunning(NodeRunning stateRunning, Timeouts timeouts) { |
| 50 | return timeouts.nodeRunning == 0 ? stateRunning : new RetryablePredicate<NodeMetadata>(stateRunning, |
| 51 | timeouts.nodeRunning); |
| 52 | } |
| 53 | |
| 54 | @Provides |
| 55 | @Singleton |
| 56 | @Named("NODE_TERMINATED") |
| 57 | protected Predicate<NodeMetadata> serverTerminated(NodeTerminated stateTerminated, Timeouts timeouts) { |
| 58 | return timeouts.nodeTerminated == 0 ? stateTerminated : new RetryablePredicate<NodeMetadata>(stateTerminated, |
| 59 | timeouts.nodeTerminated); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | @Provides |
| 64 | @Singleton |
| 65 | @Named("NODE_SUSPENDED") |
| 66 | protected Predicate<NodeMetadata> serverSuspended(NodeSuspended stateSuspended, Timeouts timeouts) { |
| 67 | return timeouts.nodeSuspended == 0 ? stateSuspended : new RetryablePredicate<NodeMetadata>(stateSuspended, |
| 68 | timeouts.nodeSuspended); |
| 69 | } |
| 70 | |
| 71 | @Provides |
| 72 | @Singleton |
| 73 | @Named("SCRIPT_COMPLETE") |
| 74 | protected Predicate<CommandUsingClient> runScriptRunning(ScriptStatusReturnsZero stateRunning, Timeouts timeouts) { |
| 75 | return timeouts.scriptComplete == 0 ? not(stateRunning) : new RetryablePredicate<CommandUsingClient>( |
| 76 | not(stateRunning), timeouts.scriptComplete); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | protected void configure() { |
| 81 | |
| 82 | } |
| 83 | } |