-
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.
refactor(cloudfoundry): move processes into their own services (#5316)
* feat(cloudfoundry): added metric event listener for outbound requests to cf * remove kork-web * refactor(cloudfoundry): move processes into their own service * change copyright to armory Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
186257e
commit 65e5e52
Showing
17 changed files
with
312 additions
and
228 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
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 |
---|---|---|
|
@@ -34,4 +34,6 @@ public interface CloudFoundryClient { | |
Tasks getTasks(); | ||
|
||
Logs getLogs(); | ||
|
||
Processes getProcesses(); | ||
} |
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
81 changes: 81 additions & 0 deletions
81
...oundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Processes.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,81 @@ | ||
/* | ||
* Copyright 2021 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.cloudfoundry.client; | ||
|
||
import static com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClientUtils.safelyCall; | ||
|
||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.api.ProcessesService; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.Process; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessStats; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ScaleProcess; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.UpdateProcess; | ||
import groovy.util.logging.Slf4j; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class Processes { | ||
|
||
private final ProcessesService api; | ||
|
||
public void scaleProcess( | ||
String guid, | ||
@Nullable Integer instances, | ||
@Nullable Integer memInMb, | ||
@Nullable Integer diskInMb) | ||
throws CloudFoundryApiException { | ||
if ((memInMb == null && diskInMb == null && instances == null) | ||
|| (Integer.valueOf(0).equals(memInMb) | ||
&& Integer.valueOf(0).equals(diskInMb) | ||
&& Integer.valueOf(0).equals(instances))) { | ||
return; | ||
} | ||
safelyCall(() -> api.scaleProcess(guid, new ScaleProcess(instances, memInMb, diskInMb))); | ||
} | ||
|
||
public Optional<Process> findProcessById(String guid) { | ||
return safelyCall(() -> api.findProcessById(guid)); | ||
} | ||
|
||
public void updateProcess( | ||
String guid, | ||
@Nullable String command, | ||
@Nullable String healthCheckType, | ||
@Nullable String healthCheckEndpoint) | ||
throws CloudFoundryApiException { | ||
final Process.HealthCheck healthCheck = | ||
healthCheckType != null ? new Process.HealthCheck().setType(healthCheckType) : null; | ||
if (healthCheckEndpoint != null && !healthCheckEndpoint.isEmpty() && healthCheck != null) { | ||
healthCheck.setData(new Process.HealthCheckData().setEndpoint(healthCheckEndpoint)); | ||
} | ||
if (command != null && command.isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"Buildpack commands cannot be empty. Please specify a custom command or set it to null to use the original buildpack command."); | ||
} | ||
|
||
safelyCall(() -> api.updateProcess(guid, new UpdateProcess(command, healthCheck))); | ||
} | ||
|
||
@Nullable | ||
public Optional<ProcessStats.State> getProcessState(String guid) throws CloudFoundryApiException { | ||
return safelyCall(() -> api.findProcessStatsById(guid)) | ||
.map(pr -> pr.getResources().stream().findAny().map(ProcessStats::getState)) | ||
.orElse(Optional.empty()); | ||
} | ||
} |
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
...main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/api/ProcessesService.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 2021 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.cloudfoundry.client.api; | ||
|
||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.Process; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ProcessResources; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.ScaleProcess; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.UpdateProcess; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Call; | ||
import retrofit2.http.*; | ||
|
||
public interface ProcessesService { | ||
|
||
@POST("/v3/processes/{guid}/actions/scale") | ||
Call<ResponseBody> scaleProcess(@Path("guid") String guid, @Body ScaleProcess scaleProcess); | ||
|
||
@PATCH("/v3/processes/{guid}") | ||
Call<Process> updateProcess(@Path("guid") String guid, @Body UpdateProcess updateProcess); | ||
|
||
@GET("/v3/processes/{guid}") | ||
Call<Process> findProcessById(@Path("guid") String guid); | ||
|
||
@GET("/v3/processes/{guid}/stats") | ||
Call<ProcessResources> findProcessStatsById(@Path("guid") String guid); | ||
} |
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.