use of com.hp.octane.integrations.services.configuration.ConfigurationService in project octane-ci-java-sdk by MicroFocus.
the class OctaneSDK method testOctaneConfigurationAndFetchAvailableWorkspaces.
/**
* This method allows to test Octane configuration prior to creating full functioning Octane client (use case - test connection in UI)
* In case of failed configuration , IllegalArgumentException is thrown
*
* @param octaneServerUrl base Octane server URL
* @param sharedSpaceId shared space ID
* @param client client / api key
* @param secret secret / api secret
* @param pluginServicesClass class that extends CIPluginServices
* @return List of available workspaces
* @throws IOException in case of basic connectivity failure
*/
public static List<Entity> testOctaneConfigurationAndFetchAvailableWorkspaces(String octaneServerUrl, String sharedSpaceId, String client, String secret, Class<? extends CIPluginServices> pluginServicesClass) throws IOException {
// instance ID is a MUST parameter but not needed for configuration validation, therefore RANDOM value provided
OctaneConfiguration configuration = OctaneConfiguration.create(UUID.randomUUID().toString(), octaneServerUrl, sharedSpaceId);
configuration.setSecret(secret);
configuration.setClient(client);
if (pluginServicesClass == null) {
throw new IllegalArgumentException("plugin services provider is invalid");
}
CIPluginServices pluginServices;
try {
pluginServices = pluginServicesClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException("failed to instantiate plugin services '" + pluginServicesClass.getSimpleName() + "'", e);
}
SDKServicesConfigurer configurer = new SDKServicesConfigurer(configuration, pluginServices);
RestService restService = RestService.newInstance(configurer);
ConfigurationService configurationService = ConfigurationService.newInstance(configurer, restService);
OctaneConnectivityStatus octaneConnectivityStatus = configurationService.validateConfigurationAndGetConnectivityStatus();
if (!CIPluginSDKUtils.isSdkSupported(octaneConnectivityStatus)) {
throw new OctaneConnectivityException(0, OctaneConnectivityException.UNSUPPORTED_SDK_VERSION_KEY, OctaneConnectivityException.UNSUPPORTED_SDK_VERSION_MESSAGE);
}
try {
EntitiesService entitiesService = EntitiesService.newInstance(configurer, restService);
List<Entity> workspaces = entitiesService.getEntities(null, /*no workspace*/
EntityConstants.Workspaces.COLLECTION_NAME, null, /*no conditions*/
Arrays.asList(EntityConstants.Base.NAME_FIELD));
return workspaces;
} catch (Exception e) {
logger.error(configuration.getLocationForLog() + "Failed to fetch workspaces in testOctaneConfigurationAndFetchAvailableWorkspaces : " + e.getMessage());
return null;
}
}
Aggregations