-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(cloudfoundry): move processes into their own services #5316
Changes from 13 commits
cf31437
b7c2f79
5bdc220
a242c8d
6149626
508f356
23cf45d
82a439f
e7467ee
62f0493
4e63e52
3e7562e
35e1496
5608bb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,6 @@ public interface CloudFoundryClient { | |
Tasks getTasks(); | ||
|
||
Logs getLogs(); | ||
|
||
Processes getProcesses(); | ||
} |
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()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v2.Page; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.*; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.Package; | ||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.model.v3.Process; | ||
import java.util.List; | ||
import java.util.Map; | ||
import okhttp3.MultipartBody; | ||
|
@@ -78,19 +77,6 @@ Call<ResponseBody> unmapRoute( | |
@DELETE("/v2/apps/{guid}/instances/{index}") | ||
Call<ResponseBody> deleteAppInstance(@Path("guid") String guid, @Path("index") String index); | ||
|
||
@POST("/v3/processes/{guid}/actions/scale") | ||
Call<ResponseBody> scaleApplication( | ||
@Path("guid") String guid, @Body ScaleApplication scaleApplication); | ||
|
||
@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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the plan to move other methods to different interfaces (like one interface for routes, one for packages, etc)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think as they get big enough it makes sense. Overall I think our nomenclature should be as similar to the cloud foundry api as possible. Another example, I renamed "scaleApplication" to "scaleProcess" since thats actually whats happening (v3/processes/:guid/actions/scale). That could cause confusion for someone looking at it for the first time if they don't have the context |
||
@POST("/v3/apps") | ||
Call<Application> createApplication(@Body CreateApplication application); | ||
|
||
|
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice removal.