-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lang): convert Groovy to Java for cloud provider classes (#4677)
- Loading branch information
Showing
7 changed files
with
180 additions
and
173 deletions.
There are no files selected for viewing
99 changes: 0 additions & 99 deletions
99
...ore/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/OnDemandMetricsSupport.groovy
This file was deleted.
Oops, something went wrong.
106 changes: 106 additions & 0 deletions
106
...-core/src/main/groovy/com/netflix/spinnaker/clouddriver/cache/OnDemandMetricsSupport.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,106 @@ | ||
/* | ||
* Copyright 2020 Armory, 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 com.netflix.spinnaker.clouddriver.cache; | ||
|
||
import com.netflix.spectator.api.Counter; | ||
import com.netflix.spectator.api.Registry; | ||
import com.netflix.spectator.api.Timer; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
|
||
public class OnDemandMetricsSupport { | ||
public static final String ON_DEMAND_TOTAL_TIME = "onDemand_total"; | ||
public static final String DATA_READ = "onDemand_read"; | ||
public static final String DATA_TRANSFORM = "onDemand_transform"; | ||
public static final String ON_DEMAND_STORE = "onDemand_store"; | ||
public static final String CACHE_WRITE = "onDemand_cache"; | ||
public static final String CACHE_EVICT = "onDemand_evict"; | ||
public static final String ON_DEMAND_ERROR = "onDemand_error"; | ||
public static final String ON_DEMAND_COUNT = "onDemand_count"; | ||
|
||
private final Timer onDemandTotal; | ||
private final Timer dataRead; | ||
private final Timer dataTransform; | ||
private final Timer onDemandStore; | ||
private final Timer cacheWrite; | ||
private final Timer cacheEvict; | ||
private final Counter onDemandErrors; | ||
private final Counter onDemandCount; | ||
|
||
public OnDemandMetricsSupport(Registry registry, OnDemandAgent agent, String onDemandType) { | ||
final String[] tags = | ||
new String[] { | ||
"providerName", | ||
agent.getProviderName(), | ||
"agentType", | ||
agent.getOnDemandAgentType(), | ||
"onDemandType", | ||
onDemandType | ||
}; | ||
this.onDemandTotal = registry.timer(ON_DEMAND_TOTAL_TIME, tags); | ||
this.dataRead = registry.timer(DATA_READ, tags); | ||
this.dataTransform = registry.timer(DATA_TRANSFORM, tags); | ||
this.onDemandStore = registry.timer(ON_DEMAND_STORE, tags); | ||
this.cacheWrite = registry.timer(CACHE_WRITE, tags); | ||
this.cacheEvict = registry.timer(CACHE_EVICT, tags); | ||
this.onDemandErrors = registry.counter(ON_DEMAND_ERROR, tags); | ||
this.onDemandCount = registry.counter(ON_DEMAND_COUNT, tags); | ||
} | ||
|
||
private <T> T record(Timer timer, Supplier<T> closure) { | ||
final long start = System.nanoTime(); | ||
try { | ||
return closure.get(); | ||
} finally { | ||
final long elapsed = System.nanoTime() - start; | ||
timer.record(elapsed, TimeUnit.NANOSECONDS); | ||
} | ||
} | ||
|
||
public <T> T readData(Supplier<T> closure) { | ||
return record(dataRead, closure); | ||
} | ||
|
||
public <T> T transformData(Supplier<T> closure) { | ||
return record(dataTransform, closure); | ||
} | ||
|
||
public <T> T onDemandStore(Supplier<T> closure) { | ||
return record(onDemandStore, closure); | ||
} | ||
|
||
public <T> T cacheWrite(Supplier<T> closure) { | ||
return record(cacheWrite, closure); | ||
} | ||
|
||
public <T> T cacheEvict(Supplier<T> closure) { | ||
return record(cacheEvict, closure); | ||
} | ||
|
||
public void countError() { | ||
onDemandErrors.increment(); | ||
} | ||
|
||
public void countOnDemand() { | ||
onDemandCount.increment(); | ||
} | ||
|
||
public void recordTotalRunTimeNanos(long nanos) { | ||
onDemandTotal.record(nanos, TimeUnit.NANOSECONDS); | ||
} | ||
} |
38 changes: 20 additions & 18 deletions
38
...ker/clouddriver/core/CloudProvider.groovy → ...naker/clouddriver/core/CloudProvider.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 |
---|---|---|
@@ -1,49 +1,51 @@ | ||
/* | ||
* Copyright 2015 Netflix, Inc. | ||
* Copyright 2020 Armory, 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 | ||
* 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.netflix.spinnaker.clouddriver.core | ||
package com.netflix.spinnaker.clouddriver.core; | ||
|
||
import java.lang.annotation.Annotation | ||
import java.lang.annotation.Annotation; | ||
|
||
/** | ||
* Different cloud providers (AWS, GCE, Titus, etc.) should implement this interface and | ||
* annotate different implementations with annotation class indicated by {@code getAnnotation} method | ||
* to identify the cloud provider specific implementations | ||
* | ||
* Different cloud providers (AWS, GCE, Titus, etc.) should implement this interface and annotate | ||
* different implementations with annotation class indicated by {@code getAnnotation} method to | ||
* identify the cloud provider specific implementations | ||
*/ | ||
interface CloudProvider { | ||
|
||
public interface CloudProvider { | ||
/** | ||
* A unique string that identifies the cloud provider implementation | ||
* | ||
* @return | ||
*/ | ||
String getId() | ||
String getId(); | ||
|
||
/** | ||
* Display name or simply the name for the cloud provider. Use {@code getID()} for uniqueness constraints | ||
* instead of this method | ||
* Display name or simply the name for the cloud provider. Use {@code getID()} for uniqueness | ||
* constraints instead of this method | ||
* | ||
* @return | ||
*/ | ||
String getDisplayName() | ||
String getDisplayName(); | ||
|
||
/** | ||
* Annotation type that can be assigned to the implementations for operations, converters, validators, etc. to enable | ||
* lookup based on the operation description name and cloud provider type | ||
* Annotation type that can be assigned to the implementations for operations, converters, | ||
* validators, etc. to enable lookup based on the operation description name and cloud provider | ||
* type | ||
* | ||
* @return | ||
*/ | ||
Class<? extends Annotation> getOperationAnnotationType() | ||
|
||
Class<? extends Annotation> getOperationAnnotationType(); | ||
} |
36 changes: 0 additions & 36 deletions
36
...core/src/main/groovy/com/netflix/spinnaker/clouddriver/deploy/DescriptionValidator.groovy
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...r-core/src/main/groovy/com/netflix/spinnaker/clouddriver/deploy/DescriptionValidator.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,30 @@ | ||
/* | ||
* Copyright 2020 Armory, 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 com.netflix.spinnaker.clouddriver.deploy; | ||
|
||
import com.netflix.spinnaker.clouddriver.orchestration.VersionedCloudProviderOperation; | ||
import java.util.List; | ||
import org.springframework.validation.Errors; | ||
|
||
public abstract class DescriptionValidator<T> implements VersionedCloudProviderOperation { | ||
public static String getValidatorName(String description) { | ||
return description + "Validator"; | ||
} | ||
|
||
public abstract void validate(List priorDescriptions, T description, Errors errors); | ||
} |
Oops, something went wrong.