All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.schedule.service.DefaultDeploymentEnvironmentProviderImpl Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.arextest.schedule.service;

import com.arextest.schedule.model.AppServiceDescriptor;
import com.arextest.schedule.model.deploy.DeploymentEnvironmentProvider;
import com.arextest.schedule.model.deploy.DeploymentImage;
import com.arextest.schedule.model.deploy.DeploymentVersion;
import com.arextest.schedule.model.deploy.ServiceInstance;
import com.arextest.schedule.model.deploy.ServiceInstanceOperation;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author jmo
 * @since 2021/9/18
 */
@Slf4j
@Component
public final class DefaultDeploymentEnvironmentProviderImpl implements
    DeploymentEnvironmentProvider {

  @Override
  public DeploymentVersion getVersion(String appId, String env) {
    DeploymentVersion deploymentVersion = new DeploymentVersion();
    deploymentVersion.setImageId("0");
    DeploymentImage deploymentImage = new DeploymentImage();
    deploymentImage.setName("Unknown");
    deploymentImage.setCreator("Unknown author");
    deploymentImage.setNote("Unknown commit message");
    deploymentVersion.setImage(deploymentImage);
    return deploymentVersion;
  }

  @Override
  public List getActiveInstanceList(AppServiceDescriptor serviceDescriptor,
      String env) {
    ServiceInstance serviceInstance = parse(env);
    if (serviceInstance != null) {
      return Collections.singletonList(serviceInstance);
    }
    return Collections.emptyList();
  }

  private ServiceInstance parse(String env) {
    try {
      URI uri = new URI(env);
      if (StringUtils.isEmpty(uri.getHost())) {
        LOGGER.error("pared empty host from '{}'", env);
        return null;
      }
      ServiceInstance instance = new ServiceInstance();
      instance.setProtocol(uri.getScheme());
      instance.setPort(uri.getPort());
      instance.setIp(uri.getHost());
      ServiceInstanceOperation operation = new ServiceInstanceOperation();
      operation.setName(uri.getPath());
      instance.setOperationList(Collections.singletonList(operation));
      instance.setUrl(env);
      return instance;
    } catch (URISyntaxException e) {
      LOGGER.error("parse active instance error : {} , {}", e.getMessage(), env, e);
    }
    return null;
  }

  @Override
  public ServiceInstance getActiveInstance(AppServiceDescriptor serviceDescriptor, String ip) {
    return parse(ip);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy