diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFAppState.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFAppState.java deleted file mode 100644 index 287f5772c..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFAppState.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public enum CFAppState { - - STOPPED, - STARTED, - UNKNOWN - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplication.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplication.java deleted file mode 100644 index bc051e004..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplication.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public interface CFApplication extends CFEntity { - //TODO: lots of this infos should be moved to application details - - int getInstances(); - int getRunningInstances(); - int getMemory(); - UUID getGuid(); - List getServices(); - String getBuildpackUrl(); - List getUris(); - CFAppState getState(); - int getDiskQuota(); - Integer getTimeout(); - String getCommand(); - String getStack(); - - Map getEnvAsMap(); - String getHealthCheckType(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationArchive.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationArchive.java deleted file mode 100644 index 52cd37157..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationArchive.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public interface CFApplicationArchive { - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationDetail.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationDetail.java deleted file mode 100644 index c36457734..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFApplicationDetail.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -import java.util.List; - -public interface CFApplicationDetail extends CFApplication { - List getInstanceDetails(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFCloudDomain.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFCloudDomain.java deleted file mode 100644 index 324a0c838..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFCloudDomain.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public interface CFCloudDomain { - String getName(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceState.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceState.java deleted file mode 100644 index 57feb7ea3..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceState.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public enum CFInstanceState { - RUNNING, CRASHED, FLAPPING, STARTING, DOWN, UNKNOWN -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceStats.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceStats.java deleted file mode 100644 index 1ba1eb539..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFInstanceStats.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public interface CFInstanceStats { - - CFInstanceState getState(); - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFOrganization.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFOrganization.java deleted file mode 100644 index d354e0d3c..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFOrganization.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -import java.util.UUID; - -public interface CFOrganization extends CFEntity { - UUID getGuid(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFSpace.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFSpace.java deleted file mode 100644 index 0568b0e55..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFSpace.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -import java.util.UUID; - -public interface CFSpace extends CFEntity { - CFOrganization getOrganization(); - UUID getGuid(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFStack.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFStack.java deleted file mode 100644 index 8cb8b34d2..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFStack.java +++ /dev/null @@ -1,15 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public interface CFStack extends CFEntity { - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java index 70c8a79e9..407b85533 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java @@ -17,57 +17,4 @@ public interface ClientRequests { List getBuildpacks() throws Exception; List getServices() throws Exception; - -// /** -// * The actual Rest API version that cloud controller claims to be. -// */ -// Version getApiVersion(); -// -// /** -// * The minimum version that the CF V2 java client claims to support. -// */ -// Version getSupportedApiVersion(); -// -// /** -// * Returns null if the application does not exist. Throws some kind of Exception if there's any other kind of problem. -// */ -// CFApplicationDetail getApplication(String appName) throws Exception; -// -// //TODO: consider removing the getXXXSupport method and directly adding the apis that these support -// // objects provide. -// SshClientSupport getSshClientSupport() throws Exception; -// -// -// void deleteApplication(String name) throws Exception; -// void logout(); -// List getDomains() throws Exception; -// -// List getApplicationsWithBasicInfo() throws Exception; -// -// List getSpaces() throws Exception; -// List getStacks() throws Exception; -// void restartApplication(String appName, CancelationToken token) throws Exception; -// void stopApplication(String appName) throws Exception; -// Flux getApplicationDetails(List appsToLookUp) throws Exception; -// String getHealthCheck(UUID appGuid) throws Exception; -// void setHealthCheck(UUID guid, String hcType) throws Exception; -// boolean applicationExists(String appName) throws Exception; -// -// //Removed in V2 -// //void createApplication(CloudApplicationDeploymentProperties deploymentProperties) throws Exception; -// -// //Added since v2: -// void push(CFPushArguments args, CancelationToken cancelationToken) throws Exception; -// Map getApplicationEnvironment(String appName) throws Exception; -// Mono deleteServiceAsync(String serviceName); -// -// /** -// * Gets current value of the client's refresh token. Note that the token is only set once it is known. -// * Initially, if a client is created via password auth, then the refreshToken won't be known until -// * some operation has been executed. -// * -// * @return Refresh token if it is already known, null otherwise. -// */ -// String getRefreshToken(); -// Mono getUserName(); } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/HealthChecks.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/HealthChecks.java deleted file mode 100644 index 96eeef68b..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/HealthChecks.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -public class HealthChecks { - - public static final String HC_NONE = "none"; - public static final String HC_PORT = "port"; - public static final String[] HC_ALL = {HC_NONE, HC_PORT}; - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/InstanceState.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/InstanceState.java deleted file mode 100644 index a1705b2bb..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/InstanceState.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009-2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -/** - * Enum used for the state of an instance - * - * Note: copied over from CF V1 client code. - * - * @author Thomas Risberg - */ -public enum InstanceState { - DOWN, STARTING, RUNNING, CRASHED, FLAPPING, UNKNOWN; - - public static InstanceState valueOfWithDefault(String s) { - try { - return InstanceState.valueOf(s); - } catch (IllegalArgumentException e) { - return InstanceState.UNKNOWN; - } - } -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshClientSupport.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshClientSupport.java deleted file mode 100644 index 45ac00bea..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshClientSupport.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal Software, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal Software, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -import java.util.UUID; - -public interface SshClientSupport { - - SshHost getSshHost() throws Exception; - String getSshUser(String appName, int instance) throws Exception; - String getSshCode() throws Exception; - - /** - * Deprecated because it is not supported with V2. Use the method based on appName instead. - */ - @Deprecated - String getSshUser(UUID appGuid, int instance) throws Exception; - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshHost.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshHost.java deleted file mode 100644 index d6103c924..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/SshHost.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2015, 2016 Pivotal Software, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal Software, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client; - -/** - * Info object containing various bits of info about the host to which an ssh - * client may wish to connect. - * - * @author Kris De Volder - */ -public class SshHost { - - final private String host; - - final private int port; - - final private String fingerPrint; - - public SshHost(String host, int port, String fingerPrint) { - super(); - this.host = host; - this.port = port; - this.fingerPrint = fingerPrint; - } - - public String getFingerPrint() { - return fingerPrint; - } - - public int getPort() { - return port; - } - - public String getHost() { - return host; - } - - @Override - public String toString() { - return "SshHost [host=" //$NON-NLS-1$ - + host + ", port=" //$NON-NLS-1$ - + port + ", fingerPrint=" //$NON-NLS-1$ - + fingerPrint + "]";//$NON-NLS-1$ - } -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ApplicationExtras.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ApplicationExtras.java deleted file mode 100644 index 4235a2ffe..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/ApplicationExtras.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import java.util.List; -import java.util.Map; - -import reactor.core.publisher.Mono; - -/** - * Extrat bits of info that are 'prefetched' asynchronously to fill - * out the CFApplication with info that C2 client doesn't initially return. - * - * @author Kris De Volder - */ -public interface ApplicationExtras { - Mono> getEnv(); - Mono> getServices(); - Mono getBuildpack(); - Mono getStack(); - Mono getTimeout(); - Mono getCommand(); - Mono getHealthCheckType(); -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationDetailData.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationDetailData.java deleted file mode 100644 index d7d2362ca..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationDetailData.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import java.util.List; - -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplicationDetail; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFInstanceStats; - -public class CFApplicationDetailData extends CFApplicationSummaryData implements CFApplicationDetail { - - private List instanceDetails; - - public CFApplicationDetailData( - CFApplicationSummaryData app, - List instanceDetails - ) { - super( - app.getName(), - app.getInstances(), - app.getRunningInstances(), - app.getMemory(), - app.getGuid(), - app.getUris(), - app.getState(), - app.getDiskQuota(), - app.extras - ); - this.instanceDetails = instanceDetails; - } - - @Override - public List getInstanceDetails() { - return instanceDetails; - } - - @Override - public String toString() { - StringBuilder buf = new StringBuilder(); - buf.append("CFApplicationDetail(\n"); - buf.append(" name = "+getName()+"\n"); - buf.append(" instance = "+getInstances()+"\n"); - buf.append(" runningInstances = "+getRunningInstances()+"\n"); - buf.append(" memory = "+getMemory()+"\n"); - buf.append(" guid = "+getGuid()+"\n"); - buf.append(" uris = "+getUris()+"\n"); - buf.append(" state = "+getState()+"\n"); - buf.append(" diskQuota = "+getDiskQuota()+"\n"); - buf.append(" instanceDetails = "+getInstanceDetails()+"\n"); - buf.append(")\n"); - return buf.toString(); - } - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationSummaryData.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationSummaryData.java deleted file mode 100644 index acb99c818..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFApplicationSummaryData.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFAppState; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplication; - -public class CFApplicationSummaryData implements CFApplication { - - private String name; - private int instances; - private int runningInstances; - private int memory; - private UUID guid; - private List uris; - private CFAppState state; - private int diskQuota; - protected ApplicationExtras extras; - - public CFApplicationSummaryData( - String name, - int instances, - int runningInstances, - int memory, - UUID guid, - List uris, - CFAppState state, - int diskQuota, - ApplicationExtras extras - ) { - super(); - this.name = name; - this.instances = instances; - this.runningInstances = runningInstances; - this.memory = memory; - this.guid = guid; - this.uris = uris; - this.state = state; - this.diskQuota = diskQuota; - this.extras = extras; - } - - @Override - public String getName() { - return name; - } - - @Override - public int getInstances() { - return instances; - } - - @Override - public int getRunningInstances() { - return runningInstances; - } - - @Override - public int getMemory() { - return memory; - } - - @Override - public UUID getGuid() { - return guid; - } - - @Override - public List getServices() { - return extras.getServices().block(); - } - - @Override - public String getBuildpackUrl() { - return extras.getBuildpack().block(); - } - - @Override - public List getUris() { - return uris; - } - - @Override - public CFAppState getState() { - return state; - } - - @Override - public int getDiskQuota() { - return diskQuota; - } - - @Override - public Integer getTimeout() { - return extras.getTimeout().block(); - } - - @Override - public String getHealthCheckType() { - return extras.getHealthCheckType().block(); - } - - @Override - public String getCommand() { - return extras.getCommand().block(); - } - - @Override - public String getStack() { - return extras.getStack().block(); - } - - @Override - public Map getEnvAsMap() { - return extras.getEnv().block(); - } - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFPushArguments.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFPushArguments.java deleted file mode 100644 index cd55e6f9e..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFPushArguments.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import java.io.File; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipFile; - -import org.springframework.ide.vscode.commons.util.ExceptionUtil; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Arguments passed to push operation. - * - * @author Kris De Volder - * @author Nieraj Singh - */ -public class CFPushArguments implements AutoCloseable { - private List routes = ImmutableList.of(); - private String appName; - private Integer memory; - private Integer diskQuota; - private Integer timeout; - private String buildpack; - private String command; - private String stack; - private String healthCheckType; - private Map env = ImmutableMap.of(); - private Integer instances; - private List services = ImmutableList.of(); - private ZipFile applicationData; - private boolean noStart = false; - - public CFPushArguments() { - } - - public String getAppName() { - return appName; - } - public void setAppName(String appName) { - this.appName = appName; - } - public Integer getMemory() { - return memory; - } - public void setMemory(Integer memory) { - this.memory = memory; - } - public Integer getDiskQuota() { - return diskQuota; - } - public void setDiskQuota(Integer diskQuota) { - this.diskQuota = diskQuota; - } - public Integer getTimeout() { - return timeout; - } - public void setTimeout(Integer timeout) { - this.timeout = timeout; - } - public String getBuildpack() { - return buildpack; - } - public void setBuildpack(String buildpack) { - this.buildpack = buildpack; - } - public String getCommand() { - return command; - } - public void setCommand(String command) { - this.command = command; - } - public String getStack() { - return stack; - } - public void setStack(String stack) { - this.stack = stack; - } - public Map getEnv() { - return env; - } - public void setEnv(Map env) { - this.env = env; - } - public Integer getInstances() { - return instances; - } - public void setInstances(Integer instances) { - this.instances = instances; - } - public List getServices() { - return services; - } - public void setServices(List services) { - this.services = services; - } - public ZipFile getApplicationData() { - return applicationData; - } - @Override - public void close() throws Exception { - if (applicationData!=null) { - applicationData.close(); - } - } - public void setApplicationData(File archive) throws Exception { - if (applicationData==null) { - ExceptionUtil.exception("Can only set this once", null); - } - this.applicationData = new ZipFile(archive); - } - public boolean isNoStart() { - return noStart; - } - public void setNoStart(boolean noStart) { - this.noStart = noStart; - } - public String getHealthCheckType() { - if (healthCheckType==null) { - return DeploymentProperties.DEFAULT_HEALTH_CHECK_TYPE; - } - return healthCheckType; - } - public void setHealthCheckType(String healthCheckType) { - this.healthCheckType = healthCheckType; - } - public List getRoutes() { - return routes; - } - public void setRoutes(Collection routes) { - this.routes = routes == null ? ImmutableList.of() : ImmutableList.copyOf(routes); - } - public void setRoutes(String... routes) { - setRoutes(ImmutableList.copyOf(routes)); - } - @Override - public String toString() { - return "CFPushArguments [appName=" + appName + ", routes=" + routes + ", memory=" + memory + ", diskQuota=" - + diskQuota + ", timeout=" + timeout + ", buildpack=" + buildpack + ", command=" + command + ", stack=" - + stack + ", env=" + env + ", instances=" + instances + ", services=" + services + ", noStart=" - + noStart + ", healthCheckType="+ healthCheckType+" ]"; - } - - -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFRoute.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFRoute.java deleted file mode 100644 index d6700dc24..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFRoute.java +++ /dev/null @@ -1,73 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import org.cloudfoundry.operations.routes.Route; - -public class CFRoute { - - final private String domain; - final private String host; - final private String path; - - public CFRoute(Route route) { - this.domain = route.getDomain(); - this.host = route.getHost(); - this.path = route.getPath(); - } - - public CFRoute(String domain, String host, String path) { - super(); - this.domain = domain; - this.host = host; - this.path = path; - } - - public String getDomain() { - return domain; - } - - public String getHost() { - return host; - } - - public String getPath() { - return path; - } - - @Override - public String toString() { - return "CFRoute [domain=" + domain + ", host=" + host + ", path=" + path + "]"; - } - - public static CFRoute.Builder builder() { - return new Builder(); - } - public static class Builder { - private String domain; - private String host; - private String path = ""; - - public CFRoute build() { - return new CFRoute(this.domain, this.host, this.path); - } - - public Builder domain(String domain) { - this.domain = domain; - return this; - } - - public Builder host(String host) { - this.host = host; - return this; - } - } -} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java index 8e434c401..da43a475a 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java @@ -10,35 +10,11 @@ *******************************************************************************/ package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; -import java.util.List; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.stream.Collectors; - -import org.cloudfoundry.client.v2.buildpacks.BuildpackResource; -import org.cloudfoundry.client.v2.domains.DomainResource; -import org.cloudfoundry.operations.applications.ApplicationDetail; -import org.cloudfoundry.operations.applications.ApplicationSummary; -import org.cloudfoundry.operations.applications.InstanceDetail; -import org.cloudfoundry.operations.organizations.OrganizationSummary; +import org.cloudfoundry.operations.buildpacks.Buildpack; import org.cloudfoundry.operations.services.ServiceInstance; import org.cloudfoundry.operations.services.ServiceInstanceType; -import org.cloudfoundry.operations.spaces.SpaceSummary; -import org.cloudfoundry.operations.stacks.Stack; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFAppState; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplication; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplicationDetail; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFCloudDomain; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFInstanceState; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFInstanceStats; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFOrganization; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFSpace; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFStack; - -import com.google.common.collect.ImmutableList; /** * Various helper methods to 'wrap' objects returned by CF client into our own @@ -48,190 +24,16 @@ import com.google.common.collect.ImmutableList; */ public class CFWrappingV2 { - private static final Logger logger = Logger.getLogger(DefaultClientRequestsV2.class.getName()); - public static CFBuildpack wrap(BuildpackResource rsrc) { - String name = rsrc.getEntity().getName(); + public static CFBuildpack wrap(Buildpack buildpack) { + String name = buildpack.getName(); return new CFBuildpackImpl(name); } - - public static CFApplicationDetail wrap(ApplicationDetail details, ApplicationExtras extras) { - if (details!=null) { - List instances = ImmutableList.copyOf( - details.getInstanceDetails() - .stream() - .map(CFWrappingV2::wrap) - .collect(Collectors.toList()) - ); - CFApplicationSummaryData summary = wrapSummary(details, extras); - return new CFApplicationDetailData( - summary, - instances - ); - } - return null; - } - - public static CFStack wrap(Stack stack) { - if (stack!=null) { - String name = stack.getName(); - return new CFStack() { - @Override - public String getName() { - return name; - } - - @Override - public String toString() { - return "CFStack("+name+")"; - } - }; - } - return null; - } - - public static CFApplicationDetail wrap( - CFApplicationSummaryData summary, - ApplicationDetail details - ) { - List instanceDetails = ImmutableList.copyOf( - details - .getInstanceDetails() - .stream() - .map(CFWrappingV2::wrap) - .collect(Collectors.toList()) - ); - return new CFApplicationDetailData(summary, instanceDetails); - } - - public static CFCloudDomain wrap(DomainResource domainRsrc) { - if (domainRsrc!=null) { - String name = domainRsrc.getEntity().getName(); - return new CFCloudDomain() { - public String getName() { - return name; - } - @Override - public String toString() { - return "CFCloudDomain("+name+")"; - } - }; - } - return null; - } - - public static CFInstanceStats wrap(InstanceDetail instanceDetail) { - return new CFInstanceStats() { - @Override - public CFInstanceState getState() { - try { - return CFInstanceState.valueOf(instanceDetail.getState()); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - return CFInstanceState.UNKNOWN; - } - } - - @Override - public String toString() { - return ""+getState(); - } - }; - } - - private static CFApplicationSummaryData wrapSummary(ApplicationDetail app, ApplicationExtras extras) { - CFAppState state; - try { - state = CFAppState.valueOf(app.getRequestedState()); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - state = CFAppState.UNKNOWN; - } - - return new CFApplicationSummaryData( - app.getName(), - app.getInstances(), - app.getRunningInstances(), - app.getMemoryLimit(), - UUID.fromString(app.getId()), - app.getUrls(), - state, - app.getDiskQuota(), - extras - ); - } - - public static CFApplication wrap(ApplicationSummary app, ApplicationExtras extras) { - CFAppState state; - try { - state = CFAppState.valueOf(app.getRequestedState()); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - state = CFAppState.UNKNOWN; - } - - return new CFApplicationSummaryData( - app.getName(), - app.getInstances(), - app.getRunningInstances(), - app.getMemoryLimit(), - UUID.fromString(app.getId()), - app.getUrls(), - state, - app.getDiskQuota(), - extras - ); - } - + public static CFServiceInstance wrap(ServiceInstance service) { return new CFServiceInstanceImpl(service); } - public static CFAppState wrapAppState(String s) { - try { - return CFAppState.valueOf(s); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - return CFAppState.UNKNOWN; - } - } - - public static CFSpace wrap(OrganizationSummary org, SpaceSummary space) { - return new CFSpace() { - @Override - public String getName() { - return space.getName(); - } - @Override - public CFOrganization getOrganization() { - return wrap(org); - } - @Override - public UUID getGuid() { - return UUID.fromString(space.getId()); - } - - @Override - public String toString() { - return "CFSpace("+org.getName()+" / "+getName()+")"; - } - }; - } - - public static CFOrganization wrap(OrganizationSummary org) { - return new CFOrganization() { - @Override - public String getName() { - return org.getName(); - } - - @Override - public UUID getGuid() { - return UUID.fromString(org.getId()); - } - }; - } - public static CFBuildpack buildpack(String name) { return new CFBuildpackImpl(name); } @@ -379,8 +181,5 @@ public class CFWrappingV2 { return false; return true; } - - } - } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java index 0374a27ea..8fef04792 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. + * Copyright (c) 2016, 2017 Pivotal, Inc. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,87 +10,22 @@ *******************************************************************************/ package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - -import java.io.IOException; -import java.time.Duration; -import java.util.Collection; import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.function.Function; -import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.applications.ApplicationEntity; -import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; -import org.cloudfoundry.client.v2.applications.GetApplicationResponse; -import org.cloudfoundry.client.v2.applications.UpdateApplicationRequest; -import org.cloudfoundry.client.v2.applications.UpdateApplicationResponse; -import org.cloudfoundry.client.v2.buildpacks.ListBuildpacksRequest; -import org.cloudfoundry.client.v2.buildpacks.ListBuildpacksResponse; -import org.cloudfoundry.client.v2.domains.DomainResource; -import org.cloudfoundry.client.v2.domains.ListDomainsRequest; -import org.cloudfoundry.client.v2.domains.ListDomainsResponse; -import org.cloudfoundry.client.v2.info.GetInfoRequest; -import org.cloudfoundry.client.v2.info.GetInfoResponse; -import org.cloudfoundry.client.v2.serviceinstances.DeleteServiceInstanceRequest; -import org.cloudfoundry.client.v2.stacks.GetStackRequest; -import org.cloudfoundry.client.v2.stacks.GetStackResponse; -import org.cloudfoundry.client.v2.userprovidedserviceinstances.DeleteUserProvidedServiceInstanceRequest; import org.cloudfoundry.operations.CloudFoundryOperations; import org.cloudfoundry.operations.DefaultCloudFoundryOperations; -import org.cloudfoundry.operations.applications.ApplicationDetail; -import org.cloudfoundry.operations.applications.DeleteApplicationRequest; -import org.cloudfoundry.operations.applications.GetApplicationEnvironmentsRequest; -import org.cloudfoundry.operations.applications.GetApplicationRequest; -import org.cloudfoundry.operations.applications.RestartApplicationRequest; -import org.cloudfoundry.operations.applications.StartApplicationRequest; -import org.cloudfoundry.operations.applications.StopApplicationRequest; -import org.cloudfoundry.operations.organizations.OrganizationDetail; -import org.cloudfoundry.operations.organizations.OrganizationInfoRequest; -import org.cloudfoundry.operations.organizations.OrganizationSummary; -import org.cloudfoundry.operations.routes.ListRoutesRequest; -import org.cloudfoundry.operations.routes.MapRouteRequest; -import org.cloudfoundry.operations.routes.UnmapRouteRequest; -import org.cloudfoundry.operations.services.BindServiceInstanceRequest; -import org.cloudfoundry.operations.services.CreateServiceInstanceRequest; -import org.cloudfoundry.operations.services.CreateUserProvidedServiceInstanceRequest; -import org.cloudfoundry.operations.services.GetServiceInstanceRequest; -import org.cloudfoundry.operations.services.ServiceInstance; -import org.cloudfoundry.operations.services.UnbindServiceInstanceRequest; -import org.cloudfoundry.operations.spaces.GetSpaceRequest; -import org.cloudfoundry.operations.spaces.SpaceDetail; -import org.cloudfoundry.reactor.tokenprovider.AbstractUaaTokenProvider; -import org.cloudfoundry.uaa.UaaClient; -import org.cloudfoundry.util.PaginationUtils; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplication; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFApplicationDetail; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFCloudDomain; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFSpace; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CFStack; import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests; import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientTimeouts; -import org.springframework.ide.vscode.commons.cloudfoundry.client.SshClientSupport; -import org.springframework.ide.vscode.commons.cloudfoundry.client.SshHost; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFClientParams; -import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.CancelationTokens.CancelationToken; import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.CloudFoundryClientCache.CFClientProvider; import org.springframework.ide.vscode.commons.util.ExceptionUtil; -import org.springframework.util.StringUtils; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -104,59 +39,15 @@ public class DefaultClientRequestsV2 implements ClientRequests { private static final Logger logger = Logger.getLogger(DefaultClientRequestsV2.class.getName()); private static final boolean DEBUG = false; - - -// static { -// if (DEBUG_REACTOR) { -// Loggers.enableExtension(new Extension() { -// @Override -// public void log(String category, java.util.logging.Level level, String msg, Object... arguments) { -// debug(category +"["+level + "] : "+MessageFormatter.format(msg, arguments).getMessage()); -// } -// }); -// } -// } - - -// TODO: it would be good not to create another 'threadpool' and use something like the below code -// instead so that eclipse job scheduler is used for reactor 'tasks'. However... the code below -// may not be 100% correct. -// private static final Callable> SCHEDULER_GROUP = () -> { -// return (Runnable task) -> { -// Job job = new Job("CF Client background task") { -// @Override -// protected IStatus run(IProgressMonitor monitor) { -// if (task!=null) { -// task.run(); -// } -// return Status.OK_STATUS; -// } -// }; -// job.setRule(JobUtil.lightRule("reactor-job-rule")); -// job.setSystem(true); -// job.schedule(); -// }; -// }; - - - private CFClientParams params; private CloudFoundryClient _client ; - private UaaClient _uaa; private CloudFoundryOperations _operations; - private Mono orgId; - private Mono info; - private Mono spaceId; - private AbstractUaaTokenProvider _tokenProvider; - private final ClientTimeouts timeouts; public DefaultClientRequestsV2(CloudFoundryClientCache clients, CFClientParams params, ClientTimeouts timeouts) { - this.params = params; CFClientProvider provider = clients.getOrCreate(params); this._client = provider.client; - this._uaa = provider.uaaClient; - this._tokenProvider = (AbstractUaaTokenProvider) provider.tokenProvider; + this._operations = DefaultCloudFoundryOperations.builder() .cloudFoundryClient(_client) .dopplerClient(provider.doppler) @@ -164,1012 +55,40 @@ public class DefaultClientRequestsV2 implements ClientRequests { .organization(params.getOrgName()) .space(params.getSpaceName()) .build(); - this.orgId = getOrgId(); - this.spaceId = getSpaceId(); - this.info = client_getInfo().cache(); + // timeouts must never be null this.timeouts = timeouts != null ? timeouts : ClientTimeouts.DEFAULT_TIMEOUTS; } - private Mono client_createOperations(OrganizationSummary org) { - return log("client.createOperations(org="+org.getName()+")", - Mono.fromCallable(() -> DefaultCloudFoundryOperations.builder() - .cloudFoundryClient(_client) - .organization(org.getName()) - .build() - ) - ); - } - - private Mono getOrgId() { - String orgName = params.getOrgName(); - if (orgName==null) { - return Mono.error(new IOException("No organization targetted")); - } else { - return operations_getOrgId().cache(); - } - } - - private Mono getSpaceId() { - String spaceName = params.getSpaceName(); - if (spaceName==null) { - return Mono.error(new IOException("No space targetted")); - } else { - return _operations.spaces().get(GetSpaceRequest.builder() - .name(params.getSpaceName()) - .build() - ) - .map(SpaceDetail::getId) - .cache(); - } - } - -// @Override - public List getApplicationsWithBasicInfo() throws Exception { - return ReactorUtils.get(operations_listApps()); - } - - private ApplicationExtras getApplicationExtras(String appName) { - //Stuff used in computing the 'extras'... - Mono appIdMono = getApplicationId(appName); - Mono entity = appIdMono - .then((appId) -> - client_getApplication(appId) - ) - .map((appResource) -> appResource.getEntity()) - .cache(); - - //The stuff returned from the getters of 'extras'... - Mono> services = prefetch("services", getBoundServicesList(appName)); - Mono> env = prefetch("env", - DefaultClientRequestsV2.this.getEnv(appName) - ); - Mono buildpack = prefetch("buildpack", - entity.then((e) -> Mono.justOrEmpty(e.getBuildpack())) - ); - - Mono stack = prefetch("stack", - entity.then((e) -> Mono.justOrEmpty(e.getStackId())) - .then((stackId) -> { - return client_getStack(stackId); - }).map((response) -> { - return response.getEntity().getName(); - }) - ); - Mono timeout = prefetch("timeout", - entity - .then((v) -> Mono.justOrEmpty(v.getHealthCheckTimeout())) - ); - - Mono command = prefetch("command", - entity.then((e) -> Mono.justOrEmpty(e.getCommand())) - ); - - Mono healthCheckType = prefetch("healthCheckType", - entity.then((e) -> Mono.justOrEmpty(e.getHealthCheckType())) - ); - - return new ApplicationExtras() { - @Override - public Mono> getServices() { - return services; - } - - @Override - public Mono> getEnv() { - return env; - } - - @Override - public Mono getBuildpack() { - return buildpack; - } - - @Override - public Mono getStack() { - return stack; - } - - public Mono getTimeout() { - return timeout; - } - - @Override - public Mono getCommand() { - return command; - } - - @Override - public Mono getHealthCheckType() { - return healthCheckType; - } - }; - } - - private Mono prefetch(String id, Mono toFetch) { - return toFetch -// .log(id + " before error handler") - .otherwise((error) -> { - logger.log(Level.SEVERE,"Failed prefetch '"+id+"'", error); - return Mono.empty(); - }) -// .log(id + " after error handler") - .cache() -// .log(id + "after cache") - ; - } - -// private Mono prefetch(Mono toFetch) { -// Mono result = toFetch -// .cache(); // It should only be fetched once. -// -// //We must ensure the 'result' is being consumed by something to force its execution: -// result -// .publishOn(SCHEDULER_GROUP) //Ensure the consume is truly async or it may block here. -// .consume((dont_care) -> {}); -// -// return result; -// } - @Override public List getServices() throws Exception { return ReactorUtils.get(timeouts.getServicesTimeout(), CancelationTokens.NULL, - log("operations.services.listInstances()", + log("operations.services.listIntances", _operations .services() .listInstances() .map(CFWrappingV2::wrap) .collectList() .map(ImmutableList::copyOf) - ) - ); - } - - /** - * Get details for a given list of applications. This does a 'best' effort getting the details for - * as many apps as possible but it does not guarantee that it will return details for each app in the - * list. This is to avoid one 'bad apple' from spoiling the whole batch. (I.e if failing to fetch details for - * some apps we can still return details for the others rather than throw an exception). - */ -// @Override - public Flux getApplicationDetails(List appsToLookUp) throws Exception { - return Flux.fromIterable(appsToLookUp) - .flatMap((CFApplication appSummary) -> { - return getApplicationDetail(appSummary.getName()) - .otherwise((error) -> { - logger.log(Level.SEVERE,"getting application details for '"+appSummary.getName()+"' failed", error); - - return Mono.empty(); - }) - .map((ApplicationDetail appDetails) -> CFWrappingV2.wrap((CFApplicationSummaryData)appSummary, appDetails)); - }); - } - - - /** - * Creates a retry 'signal factory' to be used with Flux.retryWhen. - *

- * @param timeBetween How much time to wait before retrying after a failure - * @param duration If this much time has elapsed when the error happens there will be no further retries. - * @return Functon that can be passed to retryWhen. - */ - private Function, Flux> retryInterval(Duration timeBetween, Duration duration) { - Predicate falseAfterDuration = falseAfter(duration); - return (errors) -> { - return errors.flatMap((error) -> { - if (falseAfterDuration.test(error)) { - return Mono.delay(timeBetween); - } else { - return Mono.error(error); - } - }); - }; - } - - private Predicate falseAfter(Duration timeToWait) { - return new Predicate() { - - private Long firstCalledAt; - - @Override - public boolean test(Throwable t) { - if (firstCalledAt==null) { - firstCalledAt = System.currentTimeMillis(); - } - long waitedTime = System.currentTimeMillis() - firstCalledAt; - //debug("falseAfter: remaining = "+(timeToWait.toMillis() - waitedTime)); - return waitedTime < timeToWait.toMillis(); - } - - }; - } - -// @Override - public void stopApplication(String appName) throws Exception { - ReactorUtils.get( - stopApp(appName) - ); - } - - private Mono stopApp(String appName) { - return log("operations.applications.stop(name="+appName+")", - _operations.applications().stop(StopApplicationRequest.builder() - .name(appName) - .build() - ) - ); - } - -// @Override - public void restartApplication(String appName, CancelationToken cancelationToken) throws Exception { - ReactorUtils.get(timeouts.getAppStartTimeout(), cancelationToken, - restartApp(appName) - ); - } - - private Mono restartApp(String appName) { - return log("operations.applications().restart(name="+appName+")", - _operations.applications().restart(RestartApplicationRequest.builder() - .name(appName) - .build()) - ); - } - -// @Override - public void logout() { - _operations = null; - _client = null; - } - - public boolean isLoggedOut() { - return _client==null; - } - -// @Override - public List getStacks() throws Exception { - return ReactorUtils.get( - log("operations.stacks().list()", - _operations.stacks() - .list() - .map(CFWrappingV2::wrap) - .collectList() - ) - ); - } - -// @Override - public SshClientSupport getSshClientSupport() throws Exception { - return new SshClientSupport() { - - @Override - public String getSshUser(UUID appGuid, int instance) { - return "cf:"+appGuid+"/" + instance; - } - - @Override - public String getSshUser(String appName, int instance) throws Exception { - return ReactorUtils.get( - getApplicationId(appName) - .map((guid) -> getSshUser(guid, instance)) - ); - } - - @Override - public SshHost getSshHost() throws Exception { - return ReactorUtils.get( - info.then((i) -> { - String fingerPrint = i.getApplicationSshHostKeyFingerprint(); - String host = i.getApplicationSshEndpoint(); - int port = 22; //Default ssh port - if (host!=null) { - if (host.contains(":")) { - String[] pieces = host.split(":"); - host = pieces[0]; - port = Integer.parseInt(pieces[1]); - } - } - if (host!=null) { - return Mono.just(new SshHost(host, port, fingerPrint)); - } - // Workaround for bug in Eclipse Neon.1 JDT cannot properly infer type SshHost. - // Works in Mars. Returning Mono.empty() results in compilation error in Neon.1 - return Mono.empty(); - }) - ); - } - - @Override - public String getSshCode() throws Exception { - return ReactorUtils.get( - log("operations.advanced.sshCode()", - _operations.advanced().sshCode() - ) - ); - } - }; - } - - private Mono operationsFor(OrganizationSummary org) { - return client_createOperations(org); - } - -// @Override - public List getSpaces() throws Exception { - Object it = ReactorUtils.get(timeouts.getSpacesTimeout(), log("operations.organizations().list()", - _operations.organizations() - .list() - ) - .flatMap((OrganizationSummary org) -> { - return operationsFor(org).flatMap((operations) -> - log("operations.spaces.list(org="+org.getId()+")", - operations - .spaces() - .list() - .map((space) -> CFWrappingV2.wrap(org, space)) - ) - ); - }) - .collectList() - ); - //workaround eclipse jdt bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=501949 - return (List) it; - } - -// @Override - public String getHealthCheck(UUID appGuid) throws Exception { - //XXX CF V2: getHealthcheck (via operations API) - // See: https://www.pivotaltracker.com/story/show/116462215 - return ReactorUtils.get( - client_getApplication(appGuid) - .map((response) -> response.getEntity().getHealthCheckType()) - ); - } - -// @Override - public void setHealthCheck(UUID guid, String hcType) throws Exception { - //XXX CF V2: setHealthCheck (via operations API) - // See: https://www.pivotaltracker.com/story/show/116462369 - ReactorUtils.get( - client_setHealthCheck(guid, hcType) - ); - } - -// @Override - public List getDomains() throws Exception { - //XXX CF V2: list domains using 'operations' api. - return ReactorUtils.get(Duration.ofMinutes(2), - orgId.flatMap(this::requestDomains) - .map(CFWrappingV2::wrap) - .collectList() - ); - } - - private Flux requestDomains(String orgId) { - return PaginationUtils.requestClientV2Resources((page) -> - client_listDomains(page) + ) ); } @Override public List getBuildpacks() throws Exception { - //XXX CF V2: getBuilpacks using 'operations' API. - return ReactorUtils.get(timeouts.getBuildpacksTimeout(), - PaginationUtils.requestClientV2Resources((page) -> { - return client_listBuildpacks(page); - }) - .map(CFWrappingV2::wrap) - .collectList() - ); - } - -// @Override - public CFApplicationDetail getApplication(String appName) throws Exception { - return ReactorUtils.get( - getApplicationMono(appName) - // .log("getApplication("+appName+")") - ); - } - - private Mono getApplicationMono(String appName) { - return getApplicationDetail(appName) - .map((appDetail) -> { - //TODO: we have 'real' appdetails now so we could get most of the 'application extras' info from that. - return CFWrappingV2.wrap(appDetail, getApplicationExtras(appName)); - }) - .otherwise(ReactorUtils.suppressException(IllegalArgumentException.class)); - } - - -// @Override - public void deleteApplication(String appName) throws Exception { - ReactorUtils.get( - log("operations.applications().delete(name="+appName+")", - _operations.applications().delete(DeleteApplicationRequest - .builder() - .name(appName) - .build() + return ReactorUtils.get(timeouts.getBuildpacksTimeout(), CancelationTokens.NULL, + log("operations.buildpacks.list", + _operations + .buildpacks() + .list() + .map(CFWrappingV2::wrap) + .collectList() + .map(ImmutableList::copyOf) ) - ) ); } - -// @Override - public boolean applicationExists(String appName) throws Exception { - return ReactorUtils.get( - getApplicationMono(appName) - .map((app) -> true) - .otherwiseIfEmpty(Mono.just(false)) - ); - } - - public Mono ifApplicationExists(String appName, Function> then, Mono els) throws Exception { - return getApplicationDetail(appName) - .map((app) -> Optional.of(app)) - .otherwiseIfEmpty(Mono.just(Optional.empty())) - .otherwise((error) -> Mono.just(Optional.empty())) - .then((Optional app) -> { - if (app.isPresent()) { - return then.apply(app.get()); - } else { - return els; - } - }); - } - -// @Override - public void push(CFPushArguments params, CancelationToken cancelationToken) throws Exception { - String appName = params.getAppName(); - ReactorUtils.get(timeouts.getAppStartTimeout(), cancelationToken, - ifApplicationExists(appName, - ((app) -> pushExisting(app, params)), - firstPush(params) - ) - ); - } - - private Mono pushExisting(ApplicationDetail app, CFPushArguments params) { - // TODO: push is using v1 below which was not ported to vscode CF support. -// String appName = params.getAppName(); -// UUID appId = UUID.fromString(app.getId()); -// return updateApp(appId, params) -// .then(getApplicationDetail(appName)) -// .then((appDetail) -> { -// return Flux.merge( -// setRoutes(appDetail, params.getRoutes()), -// bindAndUnbindServices(appName, params.getServices()) -// ).then(); -// }) -// .then(mono_debug("Uploading[1]...")) -// .then(Mono.fromCallable(() -> { -// debug("Uploading[2]..."); -// v1().uploadApplication(appName, params.getApplicationData()); -// debug("Uploading[2] DONE"); -// return "who cares"; -// })) -// .then(mono_debug("Uploading[1] DONE")) -// .then(params.isNoStart() -// ? stopApp(appName) -// : restartApp(appName) -// ); - throw ExceptionUtil.notImplemented("Application push not currently supported in CF vscode"); - } - -// private DefaultClientRequestsV1 v1() throws Exception { -// if (_v1==null) { -// CFClientParams v1params = new CFClientParams( -// params.getApiUrl(), -// params.getUsername(), -// CFCredentials.fromRefreshToken(getRefreshToken()), -// params.isSelfsigned(), -// params.getOrgName(), -// params.getSpaceName(), -// params.skipSslValidation() -// ); -// _v1 = new DefaultClientRequestsV1(v1params); -// } -// return _v1; -// } - - private Mono mono_debug(String string) { - return Mono.fromRunnable(() -> debug(string)); - } - - private Mono firstPush(CFPushArguments params) { - String appName = params.getAppName(); - return createApp(params) - .then(getApplicationDetail(appName)) - .then((appDetail) -> - Flux.merge( - setRoutes(appDetail, params.getRoutes()), - bindAndUnbindServices(appName, params.getServices()) - ).then() - ) - .then(Mono.fromCallable(() -> { -// v1().uploadApplication(appName, params.getApplicationData()); - return "who cares"; - })) - .then(params.isNoStart() - ? Mono.empty() - : startApp(appName) - ) - .then(); - } - - private Mono createApp(CFPushArguments params) { - return spaceId.and(getStackId(params)) - .then(function((spaceId, stackId) -> { - CreateApplicationRequest req = CreateApplicationRequest.builder() - .spaceId(spaceId) - .stackId(stackId.orElse(null)) - .name(params.getAppName()) - .memory(params.getMemory()) - .diskQuota(params.getDiskQuota()) - .healthCheckType(params.getHealthCheckType()) - .healthCheckTimeout(params.getTimeout()) - .buildpack(params.getBuildpack()) - .command(params.getCommand()) - .environmentJsons(params.getEnv()) - .instances(params.getInstances()) - .build(); - return log("client.applications.create("+req+")", - _client.applicationsV2().create(req) - ); - })) - .map(response -> UUID.fromString(response.getMetadata().getId())); - } - - private Mono> getStackId(CFPushArguments params) { - String stackName = params.getStack(); - if (stackName==null) { - return Mono.just(Optional.empty()); - } else { - return log("operations.stacks.get("+stackName+")", - _operations.stacks().get(org.cloudfoundry.operations.stacks.GetStackRequest.builder() - .name(stackName) - .build() - ) - .map((stack) -> Optional.of(stack.getId())) - ); - } - } - - - private Mono updateApp(UUID appId, CFPushArguments params) { - return getStackId(params) - .then((stackId) -> { - UpdateApplicationRequest req = UpdateApplicationRequest.builder() - .applicationId(appId.toString()) - .name(params.getAppName()) - .memory(params.getMemory()) - .diskQuota(params.getDiskQuota()) - .healthCheckType(params.getHealthCheckType()) - .healthCheckTimeout(params.getTimeout()) - .buildpack(params.getBuildpack()) - .command(params.getCommand()) - .stackId(stackId.orElse(null)) - .environmentJsons(params.getEnv()) - .instances(params.getInstances()) - .build(); - return log("client.applications.update("+req+")", - _client.applicationsV2().update(req) - ); - }) - .then(Mono.just(appId)); - } - -// public void pushV2(CFPushArguments params, CancelationToken cancelationToken) throws Exception { -// debug("Pushing app starting: "+params.getAppName()); -// //XXX CF V2: push should use 'manifest' in a future version of V2 -// PushApplicationRequest pushRequest = toPushRequest(params) -// .noStart(true) -// .noRoute(true) -// .build(); -// ReactorUtils.get(APP_START_TIMEOUT, cancelationToken, -// log("operations.applications().push("+pushRequest+")", -// _operations.applications() -// .push(pushRequest) -// ) -// .then(getApplicationDetail(params.getAppName())) -// .then(appDetail -> { -// return Flux.merge( -// setRoutes(appDetail, params.getRoutes()), -// setEnvVars(appDetail, params.getEnv()), -// bindAndUnbindServices(params.getAppName(), params.getServices()) -// ) -// .then(); -// }) -// .then(() -> { -// if (!params.isNoStart()) { -// return startApp(params.getAppName()); -// } else { -// return Mono.empty(); -// } -// }) -// ); -// debug("Pushing app succeeded: "+params.getAppName()); -// } - - private Mono getApplicationDetail(String appName) { - return log("operations.applications.get(name="+appName+")", - _operations.applications().get(GetApplicationRequest.builder() - .name(appName) - .build() - ) - ); - } - - public Mono setRoutes(ApplicationDetail appDetails, Collection desiredUrls) { - debug("setting routes for '"+appDetails.getName()+"': "+desiredUrls); - - //Carefull! It is not safe map/unnmap multiple routes in parallel. Doing so causes some of the - // operations to fail, presumably because of some 'optimisitic locking' being used in the database - // that keeps track of routes. - //To avoid this problem we must execute all that map / unmap calls in sequence! - return ReactorUtils.sequence( - unmapUndesiredRoutes(appDetails.getName(), desiredUrls), - mapDesiredRoutes(appDetails, desiredUrls) - ); - } - - public Mono setRoutes(String appName, Collection desiredUrls) { - return getApplicationDetail(appName) - .then(appDetails -> setRoutes(appDetails, desiredUrls)); - } - - private Mono mapDesiredRoutes(ApplicationDetail appDetail, Collection desiredUrls) { - Set currentUrls = ImmutableSet.copyOf(appDetail.getUrls()); - Mono> domains = getDomainNames().cache(); - String appName = appDetail.getName(); - - debug("currentUrls = "+currentUrls); - return Flux.fromIterable(desiredUrls) - .flatMap((url) -> { - if (currentUrls.contains(url)) { - debug("skipping: "+url); - return Mono.empty(); - } else { - debug("mapping: "+url); - return mapRoute(domains, appName, url); - } - }, 1) //!!!IN SEQUENCE!!! - .then(); - } - - private Mono mapRoute(Mono> domains, String appName, String desiredUrl) { - debug("mapRoute: "+appName+" -> "+desiredUrl); - return toRoute(domains, desiredUrl) - .then((CFRoute route) -> mapRoute(appName, route)) - .doOnError((e) -> { - logger.info("mapRoute FAILED!"); - }); - } - - private Mono mapRoute(String appName, CFRoute route) { - MapRouteRequest mapRouteReq = MapRouteRequest.builder() - .applicationName(appName) - .domain(route.getDomain()) - .host(route.getHost()) - .path(route.getPath()) - .build(); - return log("operations.routes.map("+mapRouteReq+")", - _operations.routes().map(mapRouteReq) - ); - } - - private Mono toRoute(Mono> domains, String desiredUrl) { - return domains.then((ds) -> { - for (String d : ds) { - //TODO: we assume that there's no 'path' component for now, which simpiflies things. What if there is a path component? - if (desiredUrl.endsWith(d)) { - String host = desiredUrl.substring(0, desiredUrl.length()-d.length()); - while (host.endsWith(".")) { - host = host.substring(0, host.length()-1); - } - CFRoute.Builder route = CFRoute.builder(); - route.domain(d); - if (StringUtils.hasText(host)) { - route.host(host); - } - return Mono.just(route.build()); - } - } - return Mono.error(new IOException("Couldn't find a domain matching "+desiredUrl)); - }); - } - - private Mono> getDomainNames() { - return orgId.flatMap(this::requestDomains) - .map((r) -> r.getEntity().getName()) - .collectList() - .map(ImmutableSet::copyOf); - } - -// private Set getUrls(ApplicationDetail app) { -// return operations.applications().get(GetApplicationRequest.builder() -// .name(appName) -// .build() -// ) -// .map((app) -> ImmutableSet.copyOf(app.getUrls())); -// } - - private Mono unmapUndesiredRoutes(String appName, Collection desiredUrls) { - return getExistingRoutes(appName) - .flatMap((route) -> { - debug("unmap? "+route); - if (desiredUrls.contains(getUrl(route))) { - debug("unmap? "+route+" SKIP"); - return Mono.empty(); - } else { - debug("unmap? "+route+" UNMAP"); - return unmapRoute(appName, route); - } - }, 1) //!!!IN SEQUENCE!!! - .then(); - } - - private String getUrl(CFRoute route) { - String url = route.getDomain(); - if (route.getHost()!=null) { - url = route.getHost() + "." + url; - } - String path = route.getPath(); - if (path!=null) { - while (path.startsWith("/")) { - path = path.substring(1); - } - if (StringUtils.hasText(path)) { - url = url +"/" +path; - } - } - return url; - } - - private Mono unmapRoute(String appName, CFRoute route) { - String path = route.getPath(); -// if (!StringUtil.hasText(path)) { -// //client doesn't like to get 'empty string' it will complain that route doesn't exist. -// path = null; -// } - UnmapRouteRequest req = UnmapRouteRequest.builder() - .applicationName(appName) - .domain(route.getDomain()) - .host(route.getHost()) - .path(path) - .build(); - return log("operations.routes.unmap("+req+")", - _operations.routes().unmap(req) - ); - } - - public Flux getExistingRoutes(String appName) { - return log("operations.routes.list(level=SPACE)", - _operations.routes().list(ListRoutesRequest.builder() - .level(org.cloudfoundry.operations.routes.Level.SPACE) - .build() - ) - ) - .flatMap((route) -> { - for (String app : route.getApplications()) { - if (app.equals(appName)) { - return Mono.just(new CFRoute(route)); - } - }; - return Mono.empty(); - }); - } - -// private static PushApplicationRequest.Builder toPushRequest(CFPushArguments params) { -// return PushApplicationRequest.builder() -// .name(params.getAppName()) -// .memory(params.getMemory()) -// .diskQuota(params.getDiskQuota()) -// .timeout(params.getTimeout()) -// .buildpack(params.getBuildpack()) -// .command(params.getCommand()) -// .stack(params.getStack()) -// .instances(params.getInstances()) -// .application(params.getApplicationData()); -// } - - public Mono bindAndUnbindServices(String appName, List _services) { - debug("bindAndUnbindServices "+_services); - Set services = ImmutableSet.copyOf(_services); - return getBoundServicesSet(appName) - .flatMap((boundServices) -> { - debug("boundServices = "+boundServices); - Set toUnbind = Sets.difference(boundServices, services); - Set toBind = Sets.difference(services, boundServices); - debug("toBind = "+toBind); - debug("toUnbind = "+toUnbind); - return Flux.merge( - bindServices(appName, toBind), - unbindServices(appName, toUnbind) - ); - }) - .then(); - } - - public Flux getBoundServices(String appName) { - return log("operations.services.listInstances()", - _operations.services().listInstances() - ) - .filter((service) -> isBoundTo(service, appName)) - .map(ServiceInstance::getName); - } - - public Mono> getBoundServicesSet(String appName) { - return getBoundServices(appName) - .collectList() - .map(ImmutableSet::copyOf); - } - - public Mono> getBoundServicesList(String appName) { - return getBoundServices(appName) - .collectList() - .map(ImmutableList::copyOf); - } - - private boolean isBoundTo(ServiceInstance service, String appName) { - return service.getApplications().stream() - .anyMatch((boundAppName) -> boundAppName.equals(appName)); - } - - private Flux bindServices(String appName, Set services) { - return Flux.fromIterable(services) - .flatMap((service) -> { - return log("operations.services().bind(appName="+appName+", services="+services+")", - _operations.services().bind(BindServiceInstanceRequest.builder() - .applicationName(appName) - .serviceInstanceName(service) - .build() - ) - ); - }); - } - - private Flux unbindServices(String appName, Set toUnbind) { - return Flux.fromIterable(toUnbind) - .flatMap((service) -> { - return log("operations.services.unbind(appName="+appName+", serviceInstanceName="+service+")", - _operations.services().unbind(UnbindServiceInstanceRequest.builder() - .applicationName(appName) - .serviceInstanceName(service) - .build() - ) - ); - }); - } - - - protected Mono startApp(String appName) { - return log("operations.applications.start(name="+appName+")", - _operations.applications() - .start(StartApplicationRequest.builder() - .name(appName) - .build() - ) - ); - } - - private Mono getApplicationId(String appName) { - return log("operations.applications.get(name="+appName+")", - _operations.applications().get(GetApplicationRequest.builder() - .name(appName) - .build() - ) - ).map((app) -> UUID.fromString(app.getId())); - } - - public Mono setEnvVars(ApplicationDetail appDetail, Map environment) { - return setEnvVars(UUID.fromString(appDetail.getId()), environment); - } - - public Mono setEnvVars(UUID appId, Map environment) { - return client_setEnv(appId, environment); - } - - public Mono setEnvVars(String appName, Map environment) { - return getApplicationId(appName) - .then((applicationId) -> setEnvVars(applicationId, environment)); - } - -// protected Publisher setEnvVar(String appName, String var, String value) { -// System.out.println("Set var starting: "+var +" = "+value); -// return operations.applications() -// .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() -// .name(appName) -// .variableName(var) -// .variableValue(value) -// .build() -// ) -// .after(() -> { -// System.out.println("Set var complete: "+var +" = "+value); -// return Mono.empty(); -// }); -// } - - public Mono createService(String name, String service, String plan) { - return log("operations.services.createInstance(instanceName="+name+",serviceName="+service+",planName="+plan+")", - _operations.services().createInstance(CreateServiceInstanceRequest.builder() - .serviceInstanceName(name) - .serviceName(service) - .planName(plan) - .build() - ) - ); - } - - public Mono createUserProvidedService(String name, Map credentials) { - return log("operations.services.createUserProvidedInstance(name="+name+")", - _operations.services().createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() - .name(name) - .credentials(credentials) - .build() - ) - ); - } - -// @Override -// public void deleteService(String serviceName) { -// deleteServiceMono(serviceName).get(); -// } - -// @Override - public Mono deleteServiceAsync(String serviceName) { - return getService(serviceName) - .then(this::deleteServiceInstance); - } - - protected Mono deleteServiceInstance(ServiceInstance s) { - switch (s.getType()) { - case MANAGED: - return client_deleteServiceInstance(s); - case USER_PROVIDED: - return client_deleteUserProvidedService(s); - default: - return Mono.error(new IllegalStateException("Unknown service type: "+s.getType())); - } - } - - protected Mono getService(String serviceName) { - return log("operations.services.getInstance(name="+serviceName+")", - _operations.services().getInstance(GetServiceInstanceRequest.builder() - .name(serviceName) - .build() - ) - ); - } - - public Mono> getEnv(String appName) { - return log("operations.applications.getEnvironments(appName="+appName+")", - _operations.applications().getEnvironments(GetApplicationEnvironmentsRequest.builder() - .name(appName) - .build() - ) - ) - .map((envs) -> envs.getUserProvided()) - .map(this::dropObjectsFromMap); - } - -// @Override - public Map getApplicationEnvironment(String appName) throws Exception { - return ReactorUtils.get(getEnv(appName)); - } - - private Map dropObjectsFromMap(Map map) { - Builder builder = ImmutableMap.builder(); - for (Entry entry : map.entrySet()) { - try { - builder.put(entry.getKey(), (String) entry.getValue()); - } catch (ClassCastException e) { - logger.log(Level.SEVERE,e.getMessage(), e); - - } - } - return builder.build(); - } - + ////////////////////////////////////////////////////////////////////////////////////////////////////// //// calls to client and operations with 'logging'. @@ -1207,129 +126,7 @@ public class DefaultClientRequestsV2 implements ClientRequests { } } - private void debug(String string) { - // TODO Auto-generated method stub - + private void debug(String msg) { + logger.log(Level.INFO, msg); } - - private Mono client_getInfo() { - return log("client.info().get()", - _client.info().get(GetInfoRequest.builder().build()) - ); - } - - private Mono operations_getOrgId() { - return log("operations.organizations.get(name="+params.getOrgName()+")", - _operations.organizations().get(OrganizationInfoRequest.builder() - .name(params.getOrgName()) - .build() - ) - .map(OrganizationDetail::getId) - ); - } - - private Mono> operations_listApps() { - return log("operations.applications.list()", - _operations.applications() - .list() - .map((appSummary) -> - CFWrappingV2.wrap(appSummary, getApplicationExtras(appSummary.getName())) - ) - .collectList() - .map(ImmutableList::copyOf) - ); - } - - private Mono client_getApplication(UUID appId) { - return log("client.applicationsV2.get(id="+appId+")", - _client.applicationsV2() - .get(org.cloudfoundry.client.v2.applications.GetApplicationRequest.builder() - .applicationId(appId.toString()) - .build() - ) - ); - } - - private Mono client_getStack(String stackId) { - return log("client.stacks.get(id="+stackId+")", - _client.stacks().get(GetStackRequest.builder() - .stackId(stackId) - .build() - ) - ); - } - - private Mono client_setHealthCheck(UUID guid, String hcType) { - return log("client.applicationsV2.update(id="+guid+", hcType="+hcType+")", - _client.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(guid.toString()) - .healthCheckType(hcType) - .build() - ) - ); - } - - private Mono client_listDomains(Integer page) { - return log("client.domains.list(page="+page+")", - _client.domains().list(ListDomainsRequest.builder() - .page(page) - // .owningOrganizationId(orgId) - .build() - ) - ); - } - - private Mono client_listBuildpacks(Integer page) { - return log("client.buildpacks.list(page="+page+")", - _client.buildpacks() - .list(ListBuildpacksRequest.builder() - .page(page) - .build() - ) - ); - } - - private Mono client_setEnv(UUID appId, Map environment) { - return log("client.applicationsV2.update(id="+appId+", env=...)", - _client.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(appId.toString()) - .environmentJsons(environment) - .build()) - .then() - ); - } - - private Mono client_deleteServiceInstance(ServiceInstance s) { - return log("client.serviceInstances.delete(id="+s.getId()+")", - _client.serviceInstances().delete(DeleteServiceInstanceRequest.builder() - .serviceInstanceId(s.getId()) - .build() - ) - .then() - ); - } - - private Mono client_deleteUserProvidedService(ServiceInstance s) { - return log("client.userProvidedServiceInstances.delete(id="+s.getId()+")", - _client.userProvidedServiceInstances().delete(DeleteUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(s.getId()) - .build() - ) - ); - } - -// @Override - public String getRefreshToken() { - return _tokenProvider.getRefreshToken(); - } - -// @Override - public Mono getUserName() { - return log("uaa.getUsername", - _uaa.getUsername() - ).timeout(timeouts.getUsernameTimeout()); - } - } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DeploymentProperties.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DeploymentProperties.java deleted file mode 100644 index 65cd42ebf..000000000 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DeploymentProperties.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 Pivotal, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Pivotal, Inc. - initial API and implementation - *******************************************************************************/ -package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Interface for Cloud Foundry application deployment properties - * - * @author Alex Boyko - * - */ -public interface DeploymentProperties { - - int DEFAULT_MEMORY = 1024; - int DEFAULT_INSTANCES = 1; - String DEFAULT_HEALTH_CHECK_TYPE = "port"; - - String getAppName(); - - int getMemory(); - - int getDiskQuota(); - - Integer getTimeout(); - - String getHealthCheckType(); - - String getBuildpack(); - - String getCommand(); - - String getStack(); - - Map getEnvironmentVariables(); - - int getInstances(); - - List getServices(); - - Set getUris(); - -} diff --git a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java index 9d082949b..8f6bd9181 100644 --- a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java +++ b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java @@ -30,7 +30,7 @@ public class CFClientTest { */ @Ignore @Test - public void testGetBuildpacksFromCliParamsTarget() throws Exception { + public void testFromCliParamsTarget() throws Exception { ClientParamsProvider cliProvider = new CfCliParamsProvider(); CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE; @@ -41,6 +41,8 @@ public class CFClientTest { List buildPacks = target.getBuildpacks(); assertTrue(!buildPacks.isEmpty()); + List services = target.getServices(); + assertTrue(!services.isEmpty()); } } diff --git a/vscode-extensions/commons/pom.xml b/vscode-extensions/commons/pom.xml index 78b1128a2..95d7c2033 100644 --- a/vscode-extensions/commons/pom.xml +++ b/vscode-extensions/commons/pom.xml @@ -49,7 +49,18 @@ spring-releases Spring Releases http://repo.spring.io/release + + false + + + spring-snapshots + Spring Snapshots + http://repo.spring.io/snapshot + + true + + @@ -63,9 +74,9 @@ 2.10 0.1.0-SNAPSHOT - 3.0.4.RELEASE + 3.0.5.BUILD-SNAPSHOT 0.6.0.RELEASE - 2.1.0.RELEASE + 2.3.0.BUILD-SNAPSHOT diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java index 602352d02..9cce8dee9 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.springframework.ide.vscode.manifest.yaml; -import java.time.Duration; import java.util.Collection; import javax.inject.Provider; @@ -18,11 +17,11 @@ import javax.inject.Provider; import org.eclipse.lsp4j.CompletionOptions; import org.eclipse.lsp4j.ServerCapabilities; import org.eclipse.lsp4j.TextDocumentSyncKind; -import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfCliParamsProvider; -import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider; import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientTimeouts; import org.springframework.ide.vscode.commons.cloudfoundry.client.CloudFoundryClientFactory; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache; +import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfCliParamsProvider; +import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider; import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.DefaultCloudFoundryClientFactoryV2; import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngine; import org.springframework.ide.vscode.commons.languageserver.completion.VscodeCompletionEngineAdapter; @@ -52,17 +51,6 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { private YamlSchema schema; private CFTargetCache cfTargetCache; - private static final ClientTimeouts VSCODE_CF_CLIENT_TIMEOUTS = new ClientTimeouts() { - - @Override - public Duration getServicesTimeout() { - // Use shorter timeouts for services because it is used in dynamic - // values for content assist - return Duration.ofSeconds(15); - } - }; - - public ManifestYamlLanguageServer() { SimpleTextDocumentService documents = getTextDocumentService(); @@ -107,7 +95,7 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { if (cfTargetCache == null) { ClientParamsProvider paramsProvider = new CfCliParamsProvider(); CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE; - cfTargetCache = new CFTargetCache(paramsProvider, clientFactory, VSCODE_CF_CLIENT_TIMEOUTS); + cfTargetCache = new CFTargetCache(paramsProvider, clientFactory, new ClientTimeouts()); } return cfTargetCache; } diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index 00010fcb7..819ee9c30 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -58,7 +58,7 @@ public class ManifestYmlSchema implements YamlSchema { // t_buildpack.parseWith(ManifestYmlValueParsers.fromHints(t_buildpack.toString(), buildpackProvider)); } - YAtomicType t_service_string = f.yatomic("String"); + YAtomicType t_service_string = f.yatomic("Service"); if (servicesProvider != null) { t_service_string.addHintProvider(servicesProvider); t_service_string.parseWith(ManifestYmlValueParsers.fromHints(t_service_string.toString(), servicesProvider));