Java Code Examples for org.springframework.cloud.CloudFactory#getCloud()

The following examples show how to use org.springframework.cloud.CloudFactory#getCloud() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectStoreFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 6 votes vote down vote up
private ObjectStoreServiceInfo getServiceInfo() {
    if (StringUtils.isEmpty(serviceName)) {
        LOGGER.warn("service name not specified in config files");
        return null;
    }
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName);
        if (serviceInfo instanceof ObjectStoreServiceInfo) {
            return (ObjectStoreServiceInfo) serviceInfo;
        }
        LOGGER.warn("Service instance did not match allowed label and plans.");
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e);
    }
    return null;
}
 
Example 2
Source File: AbstractCloudServiceConnectorFactory.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();

	if (cloud == null) {
		if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
			beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
		}
		CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
		cloud = cloudFactory.getCloud();
	}
	if (!StringUtils.hasText(serviceId)) {
		List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
		if (infos.size() != 1) {
			throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found "
				+ infos.size());
		}
		serviceId = infos.get(0).getId();
	}

	super.afterPropertiesSet();
}
 
Example 3
Source File: CustomerApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example 4
Source File: ProductApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example 5
Source File: TaxApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/**
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example 6
Source File: SaleApplicationContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/** 
 * Returns cloud object if the application runs on cloud environment
 * 
 * @return cloud object if the application runs on cloud environment
 */
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example 7
Source File: WorkerContextInitializer.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
	try {
		CloudFactory cloudFactory = new CloudFactory();
		return cloudFactory.getCloud();
	} catch (CloudException ce) {
		logger.error("no suitable cloud found");
		return null;
	}
}
 
Example 8
Source File: MicrometerConfiguration.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private DynatraceServiceInfo getDynatraceServiceInfo() {
    String serviceName = DynatraceServiceInfoCreator.DEFAULT_DYNATRACE_SERVICE_ID;
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        ServiceInfo serviceInfo = cloud.getServiceInfo(serviceName);
        if (serviceInfo instanceof DynatraceServiceInfo) {
            return (DynatraceServiceInfo) serviceInfo;
        }
        LOGGER.warn("Service instance did not match allowed name and type.");
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format("Failed to detect service info for service \"{0}\"!", serviceName), e);
    }
    return null;
}
 
Example 9
Source File: FileSystemFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private String getStoragePath(String serviceName) {
    if (StringUtils.isEmpty(serviceName)) {
        LOGGER.warn(Messages.FILE_SYSTEM_SERVICE_NAME_IS_NOT_SPECIFIED);
        return null;
    }
    try {
        CloudFactory cloudFactory = new CloudFactory();
        Cloud cloud = cloudFactory.getCloud();
        FileSystemServiceInfo serviceInfo = (FileSystemServiceInfo) cloud.getServiceInfo(serviceName);
        return serviceInfo.getStoragePath();
    } catch (CloudException e) {
        LOGGER.warn(MessageFormat.format(Messages.FAILED_TO_DETECT_FILE_SERVICE_STORAGE_PATH, serviceName), e);
    }
    return null;
}
 
Example 10
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException e) {
        return null;
    }
}
 
Example 11
Source File: ContextInitializer.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException e) {
        return null;
    }
}
 
Example 12
Source File: TestRestController.java    From bluemix-cloud-connectors with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
  try {
    CloudFactory cloudFactory = new CloudFactory();
    return cloudFactory.getCloud();
  } catch (CloudException ce) {
    return null;
  }
}
 
Example 13
Source File: AbstractWebApplicationInitializer.java    From bearchoke with Apache License 2.0 5 votes vote down vote up
protected Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException ce) {
        return null;
    }
}
 
Example 14
Source File: SpringApplicationContextInitializer.java    From spring-music with Apache License 2.0 5 votes vote down vote up
private Cloud getCloud() {
    try {
        CloudFactory cloudFactory = new CloudFactory();
        return cloudFactory.getCloud();
    } catch (CloudException ce) {
        return null;
    }
}
 
Example 15
Source File: CloudPropertiesFactoryBean.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
	ConfigurableListableBeanFactory listableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
	
	if (cloud == null) {
		if(listableBeanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
			listableBeanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME , new CloudFactory());
		}
		CloudFactory cloudFactory = listableBeanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
		cloud = cloudFactory.getCloud();
	}
}
 
Example 16
Source File: CloudScanHelper.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
private void initializeCloud(BeanDefinitionRegistry registry) {
	if (cloud != null) {
		return;
	}

	ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;

	if(beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
		beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
	}
	CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
	cloud = cloudFactory.getCloud();
}