예제 #1
0
  @SuppressWarnings("unchecked")
  public static Cartridge toCartridge(CartridgeConfig config) {
    if (config == null) {
      return null;
    }
    Cartridge cartridge = new Cartridge();

    // populate cartridge
    cartridge.setType(config.getType());
    cartridge.setDisplayName(config.getDisplayName());
    cartridge.setDescription(config.getDescription());
    cartridge.setHostName(config.getHostName());
    String[] deploymentDirs = config.getDeploymentDirs();
    if ((deploymentDirs != null) && (deploymentDirs.length > 0)) {
      cartridge.setDeploymentDirs(Arrays.asList(deploymentDirs));
    }
    cartridge.setProvider(config.getProvider());
    cartridge.setVersion(config.getVersion());
    cartridge.setBaseDir(config.getBaseDir());

    if (config.getPortMappings() != null) {
      cartridge.setPortMappings(Arrays.asList(config.getPortMappings()));
    }

    if (config.getPersistence() != null) {
      cartridge.setPersistence(config.getPersistence());
    }
    cartridge.setMultiTenant(config.isMultiTenant());
    cartridge.setDefaultAutoscalingPolicy(config.getDefaultAutoscalingPolicy());
    cartridge.setDefaultDeploymentPolicy(config.getDefaultDeploymentPolicy());
    cartridge.setServiceGroup(config.getServiceGroup());
    org.apache.stratos.cloud.controller.pojo.Properties props = config.getProperties();
    if (props != null) {
      for (Property prop : props.getProperties()) {
        cartridge.addProperty(prop.getName(), prop.getValue());
      }
    }

    // populate LB config
    cartridge.setLbConfig(config.getLbConfig());

    List<IaasProvider> iaases = FasterLookUpDataHolder.getInstance().getIaasProviders();

    // populate IaaSes
    IaasConfig[] iaasConfigs = config.getIaasConfigs();
    if (iaasConfigs != null) {
      for (IaasConfig iaasConfig : iaasConfigs) {
        if (iaasConfig != null) {
          IaasProvider iaasProvider = null;
          if (iaases != null) {
            // check whether this is a reference to a predefined IaaS.
            for (IaasProvider iaas : iaases) {
              if (iaas.getType().equals(iaasConfig.getType())) {
                iaasProvider = new IaasProvider(iaas);
                break;
              }
            }
          }

          if (iaasProvider == null) {
            iaasProvider = new IaasProvider();
            iaasProvider.setType(iaasConfig.getType());
          }

          String className = iaasConfig.getClassName();
          if (className != null) {
            iaasProvider.setClassName(className);
          }

          String name = iaasConfig.getName();
          if (name != null) {
            iaasProvider.setName(name);
          }

          String identity = iaasConfig.getIdentity();
          if (identity != null) {
            iaasProvider.setIdentity(identity);
          }

          String credential = iaasConfig.getCredential();
          if (credential != null) {
            iaasProvider.setCredential(credential);
          }

          String provider = iaasConfig.getProvider();
          if (provider != null) {
            iaasProvider.setProvider(provider);
          }
          String imageId = iaasConfig.getImageId();
          if (imageId != null) {
            iaasProvider.setImage(imageId);
          }

          byte[] payload = iaasConfig.getPayload();
          if (payload != null) {
            iaasProvider.setPayload(payload);
          }

          org.apache.stratos.cloud.controller.pojo.Properties props1 = iaasConfig.getProperties();
          if (props1 != null) {
            for (Property prop : props1.getProperties()) {
              iaasProvider.addProperty(prop.getName(), prop.getValue());
            }
          }

          NetworkInterfaces networkInterfaces = iaasConfig.getNetworkInterfaces();
          if (networkInterfaces != null && networkInterfaces.getNetworkInterfaces() != null) {
            iaasProvider.setNetworkInterfaces(networkInterfaces.getNetworkInterfaces());
          }

          cartridge.addIaasProvider(iaasProvider);
        }
      }
    }

    return cartridge;
  }
예제 #2
0
  public static CartridgeInfo toCartridgeInfo(Cartridge cartridge) {

    CartridgeInfo carInfo = new CartridgeInfo();
    carInfo.setType(cartridge.getType());
    carInfo.setDisplayName(cartridge.getDisplayName());
    carInfo.setDescription(cartridge.getDescription());
    carInfo.setHostName(cartridge.getHostName());
    carInfo.setDeploymentDirs(cartridge.getDeploymentDirs());
    carInfo.setProvider(cartridge.getProvider());
    carInfo.setVersion(cartridge.getVersion());
    carInfo.setMultiTenant(cartridge.isMultiTenant());
    carInfo.setBaseDir(cartridge.getBaseDir());
    carInfo.setLbConfig(cartridge.getLbConfig());
    carInfo.setDefaultAutoscalingPolicy(cartridge.getDefaultAutoscalingPolicy());
    carInfo.setDefaultDeploymentPolicy(cartridge.getDefaultDeploymentPolicy());
    carInfo.setPortMappings(
        cartridge.getPortMappings().toArray(new PortMapping[cartridge.getPortMappings().size()]));
    carInfo.setAppTypes(
        cartridge.getAppTypeMappings().toArray(new AppType[cartridge.getAppTypeMappings().size()]));

    List<Property> propList = new ArrayList<Property>();
    carInfo.setPersistence(cartridge.getPersistence());

    for (Iterator<?> iterator = cartridge.getProperties().entrySet().iterator();
        iterator.hasNext(); ) {
      @SuppressWarnings("unchecked")
      Map.Entry<String, String> entry = (Entry<String, String>) iterator.next();

      Property prop = new Property(entry.getKey(), entry.getValue());
      propList.add(prop);
    }
    Property[] props = new Property[propList.size()];

    carInfo.setProperties(propList.toArray(props));

    return carInfo;
  }