Skip to content

Commit

Permalink
Fixed button layout for the version IDEA 2018.2.RC. The list of AWS s…
Browse files Browse the repository at this point in the history
…treams has been ordered by event time, descendant. Added a button to load next list of AWS stream set (split by 50 items).
  • Loading branch information
satr committed Jul 22, 2018
1 parent 426c859 commit 22df771
Show file tree
Hide file tree
Showing 12 changed files with 456 additions and 219 deletions.
491 changes: 310 additions & 181 deletions sources/.idea/workspace.xml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion sources/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>io.github.satr.idea.plugin.connector.la</id>
<name>Connector for AWS Lambda</name>
<version>1.6</version>
<version>1.7.RC1</version>
<vendor email="[email protected]" url="https://satr.github.io/intellij-idea-plugin-connector-for-aws-lambda/">github.com/satr</vendor>

<description><![CDATA[
Expand All @@ -13,6 +13,10 @@

<change-notes><![CDATA[
<ul>
<li>1.7.RC1</li>
<li>Fixed button layout for the version IDEA 2018.2.RC</li>
<li>The list of AWS streams has been ordered by event time, descendant.</li>
<li>Added a button to load next list of AWS stream set (split by 50 items).</li>
<li>1.6</li>
<li>Save and restore selected jar artifact per function - implemented by <a href="https://github.com/DragoX">DragoX</a>.</li>
<li>Fix last selected function restore after relaunch - implemented by <a href="https://github.com/DragoX">DragoX</a>.</li>
Expand Down
Binary file added sources/resources/icons/iconNextAwsLogSet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sources/resources/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
import io.github.satr.common.DateTimeHelper;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Date;

public class AwsLogStreamEntity {

private String logGroupName;
private final String logStreamName;
private final LocalDateTime lastEventTimestamp;
private final LocalDateTime creationTime;
private final LocalDateTime lastEventTime;

public AwsLogStreamEntity(String logGroupName, LogStream logStream) {
this.logGroupName = logGroupName;
logStreamName = logStream.getLogStreamName();
lastEventTimestamp = DateTimeHelper.toLocalDateTime(logStream.getLastEventTimestamp());
creationTime = DateTimeHelper.toLocalDateTime(logStream.getCreationTime());
lastEventTime = DateTimeHelper.toLocalDateTime(logStream.getLastEventTimestamp());
}

public String getLogStreamName() {
Expand All @@ -31,13 +27,13 @@ public String getLogGroupName() {
return logGroupName;
}

public LocalDateTime getCreationTime() {
return creationTime;
public LocalDateTime getLastEventTime() {
return lastEventTime;
}

@Override
public String toString() {
return String.format("%s - %s : \"%s\"", DateTimeHelper.toFormattedString(creationTime),
return String.format("%s - %s : \"%s\"", DateTimeHelper.toFormattedString(lastEventTime),
DateTimeHelper.toFormattedString(lastEventTimestamp),
logStreamName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,42 @@

public class FunctionConnectorModel extends AbstractConnectorModel {
private final AWSLogs awsLogClient;
private final int awsLogStreamItemsLimit = 50;
private AWSLambda awsLambdaClient;
private static final Map<String, String> regionDescriptions;

static {
regionDescriptions = createRegionDescriptionsMap();
}

private LastLogStreamState lastLogStreamState;

private class LastLogStreamState {
private String nextToken;
private String functionName;

private LastLogStreamState(String functionName) {
this.functionName = functionName;
}

public String getNextToken() {
return nextToken;
}

public LastLogStreamState setNextToken(String token) {
this.nextToken = token;
return this;
}

public boolean hasNextToken() {
return !isEmpty(nextToken);
}

public boolean isForFunction(String functionName) {
return this.functionName.equals(functionName);
}
}

private static Map<String, String> createRegionDescriptionsMap() {
HashMap<String, String> map = new LinkedHashMap<>();
map.put("us-east-2", "US East (Ohio)");
Expand Down Expand Up @@ -111,6 +140,7 @@ public OperationValueResult<FunctionEntity> updateWithJar(final FunctionEntity f
}

public OperationValueResult<FunctionEntity> updateWithJar(final FunctionEntity functionEntity, final File file) {
resetLastLogStreamNextToken();
final OperationValueResultImpl<FunctionEntity> operationResult = new OperationValueResultImpl<>();
validateLambdaFunctionJarFile(file, operationResult);
if (operationResult.failed())
Expand All @@ -134,6 +164,7 @@ public OperationValueResult<FunctionEntity> updateWithJar(final FunctionEntity f
}

private OperationValueResult<FunctionEntity> updateFunctionCode(final FunctionEntity functionEntity, final FileChannel fileChannel) throws IOException {
resetLastLogStreamNextToken();
final OperationValueResultImpl<FunctionEntity> valueResult = new OperationValueResultImpl<>();
try {
final MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
Expand All @@ -153,6 +184,7 @@ private OperationValueResult<FunctionEntity> updateFunctionCode(final FunctionEn
public OperationValueResult<String> invokeFunction(final String functionName, final String inputText) {
OperationValueResult<String> operationResult = new OperationValueResultImpl<>();
try {
resetLastLogStreamNextToken();
InvokeRequest invokeRequest = new InvokeRequest();
invokeRequest.setFunctionName(functionName);
invokeRequest.setPayload(inputText);
Expand All @@ -176,6 +208,10 @@ public OperationValueResult<String> invokeFunction(final String functionName, fi
return operationResult;
}

public void resetLastLogStreamNextToken() {
lastLogStreamState = null;
}

private void validateLambdaFunctionJarFile(File file, OperationResult operationResult) {
if (!file.exists()) {
operationResult.addError("JAR-file does not exist.");
Expand Down Expand Up @@ -236,6 +272,7 @@ public OperationValueResult<FunctionEntity> getFunctionBy(String name) {
}

public OperationResult updateConfiguration(FunctionEntity functionEntity) {
resetLastLogStreamNextToken();
OperationResultImpl operationResult = new OperationResultImpl();
UpdateFunctionConfigurationRequest request = new UpdateFunctionConfigurationRequest()
.withFunctionName(functionEntity.getFunctionName())
Expand All @@ -254,7 +291,9 @@ public OperationResult updateConfiguration(FunctionEntity functionEntity) {
return operationResult;
}

public OperationValueResult<List<AwsLogStreamEntity>> getAwsLogStreamsFor(String functionName) {
@NotNull
public OperationValueResult<List<AwsLogStreamEntity>> getAwsLogStreamsFor(String functionName,
AwsLogRequestMode awsLogRequestMode) {
List<AwsLogStreamEntity> awsLogStreamEntities = new ArrayList<>();
OperationValueResult<List<AwsLogStreamEntity>> operationResult = new OperationValueResultImpl<>();
operationResult.setValue(awsLogStreamEntities);
Expand All @@ -263,17 +302,39 @@ public OperationValueResult<List<AwsLogStreamEntity>> getAwsLogStreamsFor(String
operationResult.addInfo("Not found log group for the function \"%s\"", functionName);
return operationResult;
}
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest().withLogGroupName(logGroup.getLogGroupName());
DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest()
.withLogGroupName(logGroup.getLogGroupName())
.withOrderBy(OrderBy.LastEventTime)
.withDescending(true)
.withLimit(awsLogStreamItemsLimit);
if (awsLogRequestMode == AwsLogRequestMode.RequestNextSet
&& lastLogStreamState != null
&& lastLogStreamState.isForFunction(functionName)
&& lastLogStreamState.hasNextToken() ) {
describeLogStreamsRequest.withNextToken(lastLogStreamState.getNextToken());
} else {
lastLogStreamState = null;
}
//TODO move backward?
DescribeLogStreamsResult describeLogStreamsResult = awsLogClient.describeLogStreams(describeLogStreamsRequest);
String nextToken = describeLogStreamsResult.getNextToken();
lastLogStreamState = getLastLogStreamStateFor(functionName).setNextToken(nextToken);
List<LogStream> logStreams = describeLogStreamsResult.getLogStreams();
for(LogStream logStream : logStreams) {
awsLogStreamEntities.add(new AwsLogStreamEntity(logGroup.getLogGroupName(), logStream));
}
awsLogStreamEntities.sort(Comparator.comparing(AwsLogStreamEntity::getCreationTime));
awsLogStreamEntities.sort(Comparator.comparing(AwsLogStreamEntity::getLastEventTime).reversed());
return operationResult;
}

public LastLogStreamState getLastLogStreamStateFor(String functionName) {
return lastLogStreamState != null && lastLogStreamState.isForFunction(functionName)
? lastLogStreamState
: new LastLogStreamState(functionName);
}

public OperationValueResult deleteAwsLogStreamsFor(String functionName) {
resetLastLogStreamNextToken();
OperationValueResult operationResult = new OperationValueResultImpl();
LogGroup logGroup = getLogGroupForAwsLambdaFunction(functionName);
if(logGroup == null) {
Expand Down Expand Up @@ -324,4 +385,8 @@ public void shutdown() {
}
}

public enum AwsLogRequestMode {
NewRequest, RequestNextSet

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public interface ConnectorPresenter {
void setAwsLogStreamEventList(AwsLogStreamEntity entity);
void setAutoRefreshAwsLog(boolean autoRefresh);
void refreshAwsLogStreams();
void runGetNextAwsLogStreamSet();
boolean roleListLoaded();
boolean initializeFunctionRoleList();
void deleteAwsLogStreams();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void refreshAll() {
FunctionEntity functionEntity = view.getSelectedFunctionEntity();
refreshFunctionConfiguration(functionEntity);
if(autoRefreshAwsLog) {
refreshAwsLogStreamList(functionEntity);
refreshAwsLogStreamList(functionEntity, FunctionConnectorModel.AwsLogRequestMode.NewRequest);
} else {
view.clearAwsLogStreamList();
}
Expand Down Expand Up @@ -253,7 +253,12 @@ public void setAutoRefreshAwsLog(boolean autoRefresh) {

@Override
public void refreshAwsLogStreams() {
refreshAwsLogStreamList(view.getSelectedFunctionEntity());
refreshAwsLogStreamList(view.getSelectedFunctionEntity(), FunctionConnectorModel.AwsLogRequestMode.NewRequest);
}

@Override
public void runGetNextAwsLogStreamSet() {
refreshAwsLogStreamList(view.getSelectedFunctionEntity(), FunctionConnectorModel.AwsLogRequestMode.RequestNextSet);
}

@Override
Expand Down Expand Up @@ -311,7 +316,7 @@ public void setAwsLogStreamEvent(AwsLogStreamEventEntity entity) {
view.setAwsLogStreamEvent(DateTimeHelper.toFormattedString(entity.getTimeStamp()), entity.getMessage());
}

private void refreshAwsLogStreamList(FunctionEntity functionEntity) {
private void refreshAwsLogStreamList(FunctionEntity functionEntity, FunctionConnectorModel.AwsLogRequestMode awsLogRequestMode) {
if(functionEntity == null) {
getLogger().logDebug("Clear AWS Log Stream list for not selected function.");
view.clearAwsLogStreamList();
Expand All @@ -320,7 +325,8 @@ private void refreshAwsLogStreamList(FunctionEntity functionEntity) {
getLogger().logDebug("Refresh AWS Log Stream list.");
view.clearAwsLogStreamEventList();
OperationValueResult<List<AwsLogStreamEntity>> getAwsLogEventsResult = getFunctionConnectorModel()
.getAwsLogStreamsFor(functionEntity.getFunctionName());
.getAwsLogStreamsFor(functionEntity.getFunctionName(),
awsLogRequestMode);
if(getAwsLogEventsResult.failed()) {
getLogger().logOperationResult(getAwsLogEventsResult);
return;
Expand Down Expand Up @@ -471,7 +477,7 @@ public void setFunction(FunctionEntity functionEntity) {
}
view.setFunctionConfiguration(functionEntity);
if(autoRefreshAwsLog) {
refreshAwsLogStreamList(functionEntity);
refreshAwsLogStreamList(functionEntity, FunctionConnectorModel.AwsLogRequestMode.NewRequest);
} else {
view.clearAwsLogStreamList();
}
Expand Down
Loading

0 comments on commit 22df771

Please sign in to comment.