io.hyscale.controller.service.ReplicaProcessingService Maven / Gradle / Ivy
The newest version!
/**
* Copyright 2019 Pramati Prism, 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.hyscale.controller.service;
import io.hyscale.commons.exception.HyscaleException;
import io.hyscale.commons.logger.TableFields;
import io.hyscale.commons.logger.TableFormatter;
import io.hyscale.commons.logger.WorkflowLogger;
import io.hyscale.commons.models.AuthConfig;
import io.hyscale.commons.models.K8sAuthorisation;
import io.hyscale.controller.builder.K8sAuthConfigBuilder;
import io.hyscale.controller.util.StatusUtil;
import io.hyscale.deployer.services.deployer.Deployer;
import io.hyscale.deployer.services.model.ReplicaInfo;
import io.hyscale.deployer.services.processor.PodParentProvider;
import io.hyscale.deployer.services.provider.K8sClientProvider;
import io.kubernetes.client.openapi.ApiClient;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Component
public class ReplicaProcessingService {
@Autowired
private Deployer deployer;
@Autowired
private K8sAuthConfigBuilder configBuilder;
@Autowired
private K8sClientProvider clientProvider;
@Autowired
private PodParentProvider podParentProvider;
public List getReplicas(String appName, String serviceName, String namespace, boolean latest) throws HyscaleException {
AuthConfig authConfig = configBuilder.getAuthConfig();
if (latest) {
return deployer.getLatestReplicas(authConfig, appName, serviceName, namespace);
} else {
return deployer.getReplicas(authConfig, appName, serviceName, namespace, true);
}
}
public boolean hasService(AuthConfig authConfig, String appName, String serviceName, String namespace) throws HyscaleException {
authConfig = authConfig == null ? configBuilder.getAuthConfig() : authConfig;
ApiClient apiClient = clientProvider.get((K8sAuthorisation) authConfig);
return podParentProvider.hasPodParent(apiClient, appName, serviceName, namespace);
}
public boolean doesReplicaExist(String replica, List replicaInfos) {
if (replicaInfos == null || replicaInfos.isEmpty()) {
return false;
}
if (StringUtils.isBlank(replica)) {
return false;
}
return replicaInfos.stream().anyMatch(each -> {
return replica.equals(each.getName());
});
}
public Optional
© 2015 - 2024 Weber Informatics LLC | Privacy Policy