Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global app prop #46

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ComponentHelper {

public ComponentHelper(ApplicationClient appClient, ComponentClient compClient, TaskListener listener,
EnvVars envVars) {
UCDeployPublisher.ts.getLogger().println("Inside Component helper");
this.appClient = appClient;
this.compClient = compClient;
this.listener = listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ public class DeployHelper {
private URI ucdUrl;

public DeployHelper(URI ucdUrl, DefaultHttpClient httpClient, TaskListener listener, EnvVars envVars) {
UCDeployPublisher.ts.getLogger().println("Inside Deploy helper");
this.ucdUrl = ucdUrl;
appClient = new ApplicationClient(ucdUrl, httpClient);
this.listener = listener;
this.envVars = envVars;
}


public static class DeployBlock {
private String deployApp;
private String deployEnv;
Expand Down Expand Up @@ -206,6 +208,8 @@ public Boolean getDeployOnlyChanged() {
public String getMethod(String uri) throws Exception{
String result ="";
HttpGet method = new HttpGet(uri);
UCDeployPublisher.ts.getLogger().println("Inside getMethod of Deploy helper ");
UCDeployPublisher.ts.getLogger().println("The response from Udeploydite client is received");
try {
HttpResponse response = UCDeploySite.client.execute(method);
int responseCode = response.getStatusLine().getStatusCode();
Expand All @@ -219,6 +223,7 @@ else if (responseCode != 200) {
if (entity != null) {
// return it as a String
result = EntityUtils.toString(entity);
UCDeployPublisher.ts.getLogger().println("The response from Udeploydite client we got is" + result);
System.out.println(result);
}
}catch (Exception e) {
Expand Down Expand Up @@ -505,12 +510,16 @@ public void runDeployment(DeployBlock deployBlock) throws IOException, JSONExcep
String uri2 = ucdUrl.toString()+"/property/propSheet/applications%26"+applicationId+"%26propSheet."+versionCount;
String data2 = deployBlock.getMethod(uri2);
JSONObject PropertyObject = new JSONObject(data2);
JSONArray array1 = new JSONArray(PropertyObject.getString("properties"));
for(int i=0; i < array1.length(); i++)
{
if(array1.getJSONObject(i).getString("secure") == "false"){
listener.getLogger().println("Env : "+array1.getJSONObject(i).getString("name")+"="+array1.getJSONObject(i).getString("value"));
deployBlock.createGlobalEnvironmentVariables(array1.getJSONObject(i).getString("name"),array1.getJSONObject(i).getString("value"));
JSONArray array1 = new JSONArray(PropertyObject.getString("properties"));
boolean isSkipProps = UCDeploySite.skipProps;
listener.getLogger().println("********** resApp value is " + isSkipProps);
if (isSkipProps == false) {
for(int i=0; i < array1.length(); i++)
{
if(array1.getJSONObject(i).getString("secure") == "false"){
listener.getLogger().println("Env : "+array1.getJSONObject(i).getString("name")+"="+array1.getJSONObject(i).getString("value"));
deployBlock.createGlobalEnvironmentVariables(array1.getJSONObject(i).getString("name"),array1.getJSONObject(i).getString("value"));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public String getDisplayName() {
* Verify connectivity to the UCD site
* @param req
* @param rsp
* @param profileName
* @param url
* @param user
* @param password
Expand All @@ -124,6 +125,7 @@ public String getDisplayName() {
public void doTestConnection(
StaplerRequest req,
StaplerResponse rsp,
@QueryParameter("profileName") final String profileName,
@QueryParameter("url") final String url,
@QueryParameter("user") final String user,
@QueryParameter("password") final String password,
Expand All @@ -133,7 +135,7 @@ public void doTestConnection(
@Override
protected void check() throws IOException, ServletException {
try {
UCDeploySite site = new UCDeploySite(null, url, user, password, trustAllCerts);
UCDeploySite site = new UCDeploySite(profileName, url, user, password, trustAllCerts, false);
site.verifyConnection();
ok("Success");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class UCDeployPublisher extends Builder implements SimpleBuildStep {

public static final GlobalConfig.GlobalConfigDescriptor GLOBALDESCRIPTOR = GlobalConfig.getGlobalConfigDescriptor();

public static hudson.model.TaskListener ts;
private String siteName;
private UserBlock altUser;
private VersionBlock component;
Expand Down Expand Up @@ -504,6 +505,7 @@ public UCDeploySite getSite() {
@Override
public void perform(final Run<?, ?> build, FilePath workspace, Launcher launcher, final TaskListener listener)
throws AbortException, InterruptedException, IOException {
ts = listener;
if (build.getResult() == Result.FAILURE || build.getResult() == Result.ABORTED) {
throw new AbortException("Skip artifacts upload to IBM UrbanCode Deploy - build failed or aborted.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class UCDeploySite implements Serializable {

private boolean trustAllCerts;

public static boolean skipProps;

public static DefaultHttpClient client;

/**
Expand All @@ -70,13 +72,15 @@ public UCDeploySite(
String url,
String user,
Secret password,
boolean trustAllCerts)
boolean trustAllCerts,
boolean skipProps)
{
this.profileName = profileName;
this.url = url;
this.user = user;
this.password = password;
this.trustAllCerts = trustAllCerts;
this.skipProps = skipProps;
client = UDRestClient.createHttpClient(user, password.toString(), trustAllCerts);
}

Expand All @@ -95,14 +99,20 @@ public UCDeploySite(
String url,
String user,
String password,
boolean trustAllCerts)
boolean trustAllCerts,
boolean skipProps)
{
this(profileName, url, user, Secret.fromString(password), trustAllCerts);
this(profileName, url, user, Secret.fromString(password), trustAllCerts, skipProps);
}

public DefaultHttpClient getClient() {
if (client == null) {
UCDeployPublisher.ts.getLogger().println("In getClient Before the UCDRestClient is called");
UCDeployPublisher.ts.getLogger().println("User is" + user);
UCDeployPublisher.ts.getLogger().println("password is" + password.toString());
client = UDRestClient.createHttpClient(user, password.toString(), trustAllCerts);
UCDeployPublisher.ts.getLogger().println("After the UCDRestClient is called");
UCDeployPublisher.ts.getLogger().println("In getClient Client that we get after the call to UCDRestClient is" + client);
}
return client;
}
Expand All @@ -118,8 +128,11 @@ public DefaultHttpClient getTempClient(String tempUser, Secret tempPassword) {
*/
public String getDisplayName() {
if (StringUtils.isEmpty(profileName)) {
UCDeployPublisher.ts.getLogger().println("In getDisplayName in if scope profileName is" + profileName);
UCDeployPublisher.ts.getLogger().println("Url returned by getDisplayName function is" + profileName);
return url;
} else {
UCDeployPublisher.ts.getLogger().println("In getDisplayName in else scope profileName is" + profileName);
return profileName;
}
}
Expand All @@ -130,6 +143,7 @@ public String getDisplayName() {
* @return the profile name
*/
public String getProfileName() {
UCDeployPublisher.ts.getLogger().println("In getProfileName profileName is" + profileName);
return profileName;
}

Expand All @@ -141,6 +155,7 @@ public String getProfileName() {
*/
@DataBoundSetter
public void setProfileName(String profileName) {
UCDeployPublisher.ts.getLogger().println("In setProfileName profileName is" + profileName);
this.profileName = profileName;
}

Expand Down Expand Up @@ -195,7 +210,7 @@ public String getUser() {
/**
* Sets the username.
*
* @param username
* @param user
* the new username
*/
@DataBoundSetter
Expand Down Expand Up @@ -242,19 +257,41 @@ public void setTrustAllCerts(boolean trustAllCerts) {
this.trustAllCerts = trustAllCerts;
}

/**
* Gets skipProps
*
* @return skipProps
*/
public boolean isSkipProps() {
return skipProps;
}

/**
* Sets skipProps
*
* @param skipProps
*/
@DataBoundSetter
public void setSkipProps(boolean skipProps) {
this.skipProps = skipProps;
}

/**
* Test whether the client can connect to the UCD site
*
* @throws Exception
*/
public void verifyConnection() throws Exception {
URI uri = UriBuilder.fromPath(url).path("rest").path("state").build();
UCDeployPublisher.ts.getLogger().println("In verifyConnection the uri we get is" + uri);
executeJSONGet(uri);
}

public void executeJSONGet(URI uri) throws Exception {
String result = null;
UCDeployPublisher.ts.getLogger().println("In executeJSONGet the result we get is" + result);
HttpClient client = getClient();
UCDeployPublisher.ts.getLogger().println("In executeJSONGet the client we get is" + client);
HttpGet method = new HttpGet(uri.toString());
try {
HttpResponse response = client.execute(method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class VersionHelper {
private EnvVars envVars;

public VersionHelper(URI ucdUrl, DefaultHttpClient httpClient, TaskListener listener, EnvVars envVars) {
UCDeployPublisher.ts.getLogger().println("Inside version Helper");
appClient = new ApplicationClient(ucdUrl, httpClient);
compClient = new ComponentClient(ucdUrl, httpClient);
propClient = new PropertyClient(ucdUrl, httpClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<f:entry title="Trust All Certificates" help="${helpURL}/global/trust.html">
<f:checkbox name="trustAllCerts" checked="${site.trustAllCerts}"/>
</f:entry>
<f:entry title="Skip Application Properties import" help="${helpURL}/global/trust.html">
<f:checkbox name="skipProps" checked="${site.skipProps}"/>
</f:entry>
<f:entry title="">
<div style="text-align: right">
<f:repeatableDeleteButton/>
Expand All @@ -33,4 +36,4 @@
</f:repeatable>
</f:entry>
</f:section>
</j:jelly>
</j:jelly>