Skip to content

Commit e6977bb

Browse files
committed
Issue #120: Update project log support
1 parent 040aaa7 commit e6977bb

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/MicroclimateApplication.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import java.net.MalformedURLException;
1515
import java.net.URL;
16-
import java.util.Collections;
16+
import java.util.ArrayList;
1717
import java.util.List;
1818

1919
import org.eclipse.core.runtime.IPath;
@@ -48,7 +48,7 @@ public class MicroclimateApplication {
4848
private String containerId;
4949
private ProjectCapabilities projectCapabilities;
5050
private String action;
51-
private List<ProjectLogInfo> logInfos = Collections.emptyList();
51+
private List<ProjectLogInfo> logInfos = new ArrayList<ProjectLogInfo>();
5252
private boolean metricsAvailable = false;
5353

5454
// Must be updated whenever httpPort changes. Can be null
@@ -140,7 +140,35 @@ public synchronized void setAction(String action) {
140140
this.action = action;
141141
}
142142

143+
public synchronized void addLogInfos(List<ProjectLogInfo> newLogInfos) {
144+
if (newLogInfos == null || newLogInfos.isEmpty()) {
145+
MCLogger.logError("Trying to add empty log infos to project: " + name);
146+
return;
147+
}
148+
if (this.logInfos == null || this.logInfos.isEmpty()) {
149+
this.logInfos = newLogInfos;
150+
return;
151+
}
152+
for (ProjectLogInfo newLogInfo : newLogInfos) {
153+
boolean found = false;
154+
for (ProjectLogInfo logInfo : this.logInfos) {
155+
// There should not be more than one log with the same name for a project
156+
if (logInfo.logName.equals(newLogInfo.logName)) {
157+
found = true;
158+
break;
159+
}
160+
}
161+
if (!found) {
162+
this.logInfos.add(newLogInfo);
163+
}
164+
}
165+
}
166+
143167
public synchronized void setLogInfos(List<ProjectLogInfo> logInfos) {
168+
if (logInfos == null) {
169+
MCLogger.logError("The logs should not be set to null for project: " + name);
170+
return;
171+
}
144172
this.logInfos = logInfos;
145173
}
146174

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateConnection.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,16 @@ public List<ProjectLogInfo> requestProjectLogs(MicroclimateApplication app) thro
468468
return logList;
469469
}
470470

471-
private List<ProjectLogInfo> getLogs(JSONArray logs, String type) throws JSONException {
471+
public static List<ProjectLogInfo> getLogs(JSONArray logs, String type) throws JSONException {
472472
List<ProjectLogInfo> logList = new ArrayList<ProjectLogInfo>();
473473
if (logs != null) {
474474
for (int i = 0; i < logs.length(); i++) {
475475
JSONObject log = logs.getJSONObject(i);
476476
if (log.has(MCConstants.KEY_LOG_NAME)) {
477477
String logName = log.getString(MCConstants.KEY_LOG_NAME);
478+
if ("-".equals(logName)) {
479+
continue;
480+
}
478481
String workspacePath = null;
479482
if (log.has(MCConstants.KEY_LOG_WORKSPACE_PATH)) {
480483
workspacePath = log.getString(MCConstants.KEY_LOG_WORKSPACE_PATH);

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/connection/MicroclimateSocket.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.net.URISyntaxException;
1717
import java.util.HashMap;
1818
import java.util.HashSet;
19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
2122

@@ -28,6 +29,7 @@
2829
import com.ibm.microclimate.core.internal.MCUtil;
2930
import com.ibm.microclimate.core.internal.MicroclimateApplication;
3031
import com.ibm.microclimate.core.internal.console.OldSocketConsole;
32+
import com.ibm.microclimate.core.internal.console.ProjectLogInfo;
3133
import com.ibm.microclimate.core.internal.console.SocketConsole;
3234
import com.ibm.microclimate.core.internal.constants.MCConstants;
3335
import com.ibm.microclimate.core.internal.constants.ProjectType;
@@ -76,6 +78,7 @@ public class MicroclimateSocket {
7678
EVENT_CONTAINER_LOGS = "container-logs", //$NON-NLS-1$
7779
EVENT_PROJECT_VALIDATED = "projectValidated", //$NON-NLS-1$
7880
EVENT_LOG_UPDATE = "log-update", //$NON-NLS-1$
81+
EVENT_PROJECT_LOGS_LIST_CHANGED = "projectLogsListChanged", //$NON-NLS-1$
7982
EVENT_PROJECT_SETTINGS_CHANGED = "projectSettingsChanged"; //$NON-NLS-1$
8083

8184
public MicroclimateSocket(MicroclimateConnection mcConnection) throws URISyntaxException {
@@ -238,6 +241,19 @@ public void call(Object... arg0) {
238241
}
239242
}
240243
})
244+
.on(EVENT_PROJECT_LOGS_LIST_CHANGED, new Emitter.Listener() {
245+
@Override
246+
public void call(Object... arg0) {
247+
MCLogger.log(EVENT_PROJECT_LOGS_LIST_CHANGED + ": " + arg0[0].toString()); //$NON-NLS-1$
248+
249+
try {
250+
JSONObject event = new JSONObject(arg0[0].toString());
251+
onProjectLogsListChanged(event);
252+
} catch (JSONException e) {
253+
MCLogger.logError("Error parsing JSON: " + arg0[0].toString(), e); //$NON-NLS-1$
254+
}
255+
}
256+
})
241257
.on(EVENT_LOG_UPDATE, new Emitter.Listener() {
242258
@Override
243259
public void call(Object... arg0) {
@@ -527,6 +543,31 @@ private void onLogUpdate(JSONObject event) throws JSONException {
527543
}
528544
}
529545

546+
private void onProjectLogsListChanged(JSONObject event) throws JSONException {
547+
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
548+
MicroclimateApplication app = mcConnection.getAppByID(projectID);
549+
if (app == null) {
550+
// Likely a new project is being created
551+
mcConnection.refreshApps(projectID);
552+
MCUtil.updateConnection(mcConnection);
553+
return;
554+
}
555+
556+
String type;
557+
if (event.has(MCConstants.KEY_LOG_BUILD)) {
558+
type = MCConstants.KEY_LOG_BUILD;
559+
JSONArray logs = event.getJSONArray(MCConstants.KEY_LOG_BUILD);
560+
List<ProjectLogInfo> logInfos = MicroclimateConnection.getLogs(logs, type);
561+
app.addLogInfos(logInfos);
562+
}
563+
if (event.has(MCConstants.KEY_LOG_APP)) {
564+
type = MCConstants.KEY_LOG_APP;
565+
JSONArray logs = event.getJSONArray(MCConstants.KEY_LOG_APP);
566+
List<ProjectLogInfo> logInfos = MicroclimateConnection.getLogs(logs, type);
567+
app.addLogInfos(logInfos);
568+
}
569+
}
570+
530571
private void onValidationEvent(JSONObject event) throws JSONException {
531572
String projectID = event.getString(MCConstants.KEY_PROJECT_ID);
532573
MicroclimateApplication app = mcConnection.getAppByID(projectID);

0 commit comments

Comments
 (0)