private void loadOpenShiftData() { final ProjectConfigDto projectConfig = appContext.getCurrentProject().getRootProject(); view.setApplicationName(projectConfig.getName()); view.show(); osService .getProjects() .then( new Operation<List<Project>>() { @Override public void apply(List<Project> projects) throws OperationException { if (projects == null || projects.isEmpty()) { return; } osProjects.clear(); osProjects.addAll(unmodifiableList(projects)); view.setProjects(osProjects); } }) .then( osService .getImageStreams("openshift", null) .then( new Operation<List<ImageStream>>() { @Override public void apply(List<ImageStream> streams) throws OperationException { if (streams == null || streams.isEmpty()) { return; } osImageStreams = unmodifiableList(streams); final List<String> imageNames = Lists.transform( osImageStreams, new com.google.common.base.Function<ImageStream, String>() { @Override public String apply(ImageStream input) { return input.getMetadata().getName(); } }); view.setImages(imageNames); view.setLabels(Collections.<KeyValue>emptyList()); } })); applicationManager .getApplicationNamesByNamespaces() .then( new Operation<List<Pair<String, String>>>() { @Override public void apply(List<Pair<String, String>> arg) throws OperationException { osApplications.clear(); osApplications.addAll(arg); } }); }
private Promise<ImageStreamTag> setActiveImageTag(final ImageStream stream) { return osService .getImageStreamTag("openshift", stream.getMetadata().getName(), "latest") .thenPromise( new Function<ImageStreamTag, Promise<ImageStreamTag>>() { @Override public Promise<ImageStreamTag> apply(ImageStreamTag streamTag) throws FunctionException { osActiveStreamTag = streamTag; final DockerImageMetadata dockerImageMetadata = streamTag.getImage().getDockerImageMetadata(); List<String> envs = (dockerImageMetadata.getConfig() != null) ? dockerImageMetadata.getConfig().getEnv() : dockerImageMetadata.getContainerConfig().getEnv(); List<KeyValue> variables = new ArrayList<>(); for (String env : envs) { String[] keyValuePair = env.split("="); if (keyValuePair.length != 2) { continue; } variables.add(new KeyValue(keyValuePair[0], keyValuePair[1])); } view.setEnvironmentVariables(variables); return Promises.resolve(streamTag); } }); }
private void loadBuildConfig() { final Resource resource = appContext.getResource(); if (resource == null) { return; } final Optional<Project> project = resource.getRelatedProject(); if (project.isPresent()) { String namespace = project.get().getAttribute(OPENSHIFT_NAMESPACE_VARIABLE_NAME); String application = project.get().getAttribute(OPENSHIFT_APPLICATION_VARIABLE_NAME); service.getBuildConfigs(namespace, application).then(showBuildConfigs()).catchError(onFail()); } }
@Override public void onSaveClicked() { buildConfig.getSpec().getSource().setContextDir(view.getSourceContextDir()); buildConfig.getSpec().getSource().getGit().setRef(view.getSourceReference()); buildConfig.getSpec().getSource().getGit().setUri(view.getSourceUrl()); service .updateBuildConfig(buildConfig) .then( new Operation<BuildConfig>() { @Override public void apply(BuildConfig arg) throws OperationException { buildConfig = arg; setBuildSource(buildConfig.getSpec().getSource()); } }) .catchError(onFail()); }
@Override public void onDeployClicked() { Promise<Project> projectPromise; view.showLoader(true); switch (view.getMode()) { case CREATE_NEW_PROJECT: String osProjectName = view.getOpenShiftProjectName(); String osProjectDisplayName = view.getOpenShiftProjectDisplayName(); String osProjectDescription = view.getOpenShiftProjectDescription(); // create new project ProjectRequest request = newDto(ProjectRequest.class) .withApiVersion(API_VERSION) .withDisplayName(osProjectDisplayName) .withDescription(osProjectDescription) .withMetadata(newDto(ObjectMeta.class).withName(osProjectName)); projectPromise = osService.createProject(request); break; case SELECT_EXISTING_PROJECT: default: Project osSelectedProject = view.getOpenShiftSelectedProject(); projectPromise = Promises.resolve(osSelectedProject); } projectPromise .then( new Operation<Project>() { @Override public void apply(final Project project) throws OperationException { final Map<String, String> labels = new HashMap<>(); labels.put("generatedby", "Che"); labels.put("application", osAppName); for (KeyValue label : view.getLabels()) { labels.put(label.getKey(), label.getValue()); } final DockerImageMetadata imageMetadata = osActiveStreamTag.getImage().getDockerImageMetadata(); Object exposedPorts = (imageMetadata.getConfig() != null) ? imageMetadata.getConfig().getExposedPorts() : imageMetadata.getContainerConfig().getExposedPorts(); List<ContainerPort> ports = parsePorts(exposedPorts); String namespace = project.getMetadata().getName(); List<Promise<?>> promises = new ArrayList<>(); promises.add(osService.createImageStream(generateImageStream(namespace, labels))); promises.add(osService.createBuildConfig(generateBuildConfig(namespace, labels))); promises.add( osService.createDeploymentConfig(generateDeploymentConfig(namespace, labels))); promises.add(osService.createRoute(generateRoute(namespace, labels))); if (!ports.isEmpty()) { promises.add( osService.createService( generateService(namespace, getFirstPort(ports), labels))); } Promises.all(promises.toArray(new Promise[promises.size()])) .then( new Operation<JsArrayMixed>() { @Override public void apply(JsArrayMixed arg) throws OperationException { view.showLoader(false); view.hide(); notificationManager.notify( locale.deployProjectSuccess( appContext.getCurrentProject().getRootProject().getName()), SUCCESS, true); setupMixin(project); } }) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError arg) throws OperationException { handleError(arg); } }); } }) .catchError( new Operation<PromiseError>() { @Override public void apply(PromiseError arg) throws OperationException { handleError(arg); } }); }
private void getWebHooks(BuildConfig buildConfig) { service .getWebhooks(buildConfig.getMetadata().getNamespace(), buildConfig.getMetadata().getName()) .then(showWebhooks()) .catchError(onFail()); }