-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathFunctionComputeClientTest.java
3482 lines (2996 loc) · 162 KB
/
FunctionComputeClientTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.aliyuncs.fc;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.auth.BasicSessionCredentials;
import com.aliyuncs.auth.InstanceProfileCredentialsProvider;
import com.aliyuncs.fc.auth.AcsURLEncoder;
import com.aliyuncs.fc.auth.SignURLConfig;
import com.aliyuncs.fc.client.FunctionComputeClient;
import com.aliyuncs.fc.client.PopClient;
import com.aliyuncs.fc.config.Config;
import com.aliyuncs.fc.constants.Const;
import com.aliyuncs.fc.exceptions.ClientException;
import com.aliyuncs.fc.exceptions.ErrorCodes;
import com.aliyuncs.fc.model.*;
import com.aliyuncs.fc.model.NasConfig.NasMountConfig;
import com.aliyuncs.fc.request.*;
import com.aliyuncs.fc.response.*;
import com.aliyuncs.fc.utils.Util;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.aliyuncs.sts.model.v20150401.AssumeRoleRequest;
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse;
import com.aliyuncs.sts.model.v20150401.AssumeRoleResponse.Credentials;
import com.google.common.base.Strings;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
import org.junit.*;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.aliyuncs.fc.constants.Const.DEFAULT_REGEX;
import static com.aliyuncs.fc.constants.Const.NONE;
import static com.aliyuncs.fc.constants.HeaderKeys.OPENTRACING_SPANCONTEXT;
import static com.aliyuncs.fc.constants.HeaderKeys.OPENTRACING_SPANCONTEXT_BAGGAGE_PREFIX;
import static com.aliyuncs.fc.model.HttpAuthType.ANONYMOUS;
import static com.aliyuncs.fc.model.HttpAuthType.FUNCTION;
import static com.aliyuncs.fc.model.HttpMethod.*;
import static java.util.Arrays.asList;
import static java.util.Arrays.deepEquals;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Validation for FunctionComputeClient, tests including create/list/get/update
* service/function/trigger
*/
public class FunctionComputeClientTest {
public static final String STS_API_VERSION = "2015-04-01";
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
private static final String VALIDATE_MSG = "cannot be blank";
private static final String REGION = System.getenv("REGION");
private static final String ENDPOINT = System.getenv("ENDPOINT");
private static final String ROLE = System.getenv("ROLE");
private static final String STS_ROLE = System.getenv("STS_ROLE");
private static final String ACCESS_KEY = System.getenv("ACCESS_KEY");
private static final String SECRET_KEY = System.getenv("SECRET_KEY");
private static final String ACCOUNT_ID = System.getenv("ACCOUNT_ID");
private static final String CODE_BUCKET = System.getenv("CODE_BUCKET");
private static final String INVOCATION_ROLE = System.getenv("INVOCATION_ROLE");
private static final String LOG_PROJECT = System.getenv("LOG_PROJECT");
private static final String LOG_STORE = System.getenv("LOG_STORE");
private static final String VPC_ID = System.getenv("VPC_ID");
private static final String VSWITCH_IDS = System.getenv("VSWITCH_IDS");
private static final String SECURITY_GROUP_ID = System.getenv("SECURITY_GROUP_ID");
private static final String USER_ID = System.getenv("USER_ID");
private static final String GROUP_ID = System.getenv("GROUP_ID");
private static final String NAS_SERVER_ADDR = System.getenv("NAS_SERVER_ADDR");
private static final String NAS_MOUNT_DIR = System.getenv("NAS_MOUNT_DIR");
private static final String PUBLIC_KEY_CERTIFICATE_01 = System.getenv("PUBLIC_KEY_CERTIFICATE_01");
private static final String PRIVATE_KEY_01 = System.getenv("PRIVATE_KEY_01");
private static final String PUBLIC_KEY_CERTIFICATE_02 = System.getenv("PUBLIC_KEY_CERTIFICATE_02");
private static final String PRIVATE_KEY_02 = System.getenv("PRIVATE_KEY_02");
private static final String JAEGER_ENDPOINT = System.getenv("JAEGER_ENDPOINT");
private static final String OSS_SOURCE_ARN =
String.format("acs:oss:%s:%s:%s", REGION, ACCOUNT_ID, CODE_BUCKET);
private static final String LOG_SOURCE_ARN =
String.format("acs:log:%s:%s:project/%s", REGION, ACCOUNT_ID, LOG_PROJECT);
private static final String CDN_SOURCE_ARN =
String.format("acs:cdn:*:%s", ACCOUNT_ID);
private static final String SERVICE_NAME = "testServiceJavaSDK";
private static final String SERVICE_DESC_OLD = "service desc";
private static final String SERVICE_DESC_NEW = "service desc updated";
private static final String FUNCTION_NAME = "testFunction";
private static final String FUNCTION_DESC_OLD = "function desc";
private static final String FUNCTION_DESC_NEW = "function desc updated";
private static final String TRIGGER_NAME = "testTrigger";
private static final String TRIGGER_TYPE_OSS = "oss";
private static final String TRIGGER_TYPE_HTTP = "http";
private static final String TRIGGER_TYPE_LOG = "log";
private static final String TRIGGER_TYPE_CDN = "cdn_events";
private static final String TRIGGER_TYPE_TIMER = "timer";
private static final String CUSTOMDOMAIN_NAME = String.format("java-sdk.cn-hongkong.%s.cname-test.functioncompute.com", ACCOUNT_ID);
private static final String CERT_NAME = "CERT_NAME";
private static final Gson gson = new Gson();
private FunctionComputeClient client;
@BeforeClass
public static void setupSuite() {
System.out.println("ENDPOINT: " + ENDPOINT);
System.out.println("ROLE: " + ROLE);
System.out.println("VPC_ID: " + VPC_ID);
System.out.println("STS_ROLE: " + STS_ROLE);
}
@Before
public void setup() {
// Create or clean up everything under the test service
client = new FunctionComputeClient(REGION, ACCOUNT_ID, ACCESS_KEY, SECRET_KEY);
if (!Strings.isNullOrEmpty(ENDPOINT)) {
client.setEndpoint(ENDPOINT);
}
GetServiceRequest getSReq = new GetServiceRequest(SERVICE_NAME);
try {
client.getService(getSReq);
cleanUpAliases(SERVICE_NAME);
cleanUpVersions(SERVICE_NAME);
cleanUpFunctions(SERVICE_NAME);
cleanupService(SERVICE_NAME);
cleanUpFunctions(SERVICE_NAME + "-nas");
cleanupService(SERVICE_NAME + "-nas");
} catch (ClientException e) {
if (!ErrorCodes.SERVICE_NOT_FOUND.equals(e.getErrorCode())) {
throw e;
}
}
}
public FunctionComputeClient overrideFCClient(boolean useSts, boolean useHttps)
throws com.aliyuncs.exceptions.ClientException {
if (useSts) {
Credentials creds = getAssumeRoleCredentials(null);
FunctionComputeClient fcClient = new FunctionComputeClient(
new Config(REGION, ACCOUNT_ID,
creds.getAccessKeyId(), creds.getAccessKeySecret(), creds.getSecurityToken(),
useHttps));
if (!Strings.isNullOrEmpty(ENDPOINT)) {
fcClient.setEndpoint(ENDPOINT);
}
return fcClient;
}
return new FunctionComputeClient(new Config(REGION, ACCOUNT_ID,
ACCESS_KEY, SECRET_KEY, null, useHttps));
}
private void cleanupService(String serviceName) {
DeleteServiceRequest request = new DeleteServiceRequest(serviceName);
try {
client.deleteService(request);
} catch (ClientException e) {
if (!ErrorCodes.SERVICE_NOT_FOUND.equals(e.getErrorCode())) {
throw e;
}
}
System.out.println("Service " + serviceName + " is deleted");
}
private void cleanupProvision(String serviceName, String aliasName, String functionName) {
Integer target = 0;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(new ScheduledAction[0]);
PutProvisionConfigResponse provisionConfigResponse = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse.getStatus());
assertEquals(target, provisionConfigResponse.getTarget());
try {
// retry 30s for release provision container,
int retryTimes = 0;
while (retryTimes < 30) {
// get provisionConfig
GetProvisionConfigRequest getProvisionConfigRequest = new GetProvisionConfigRequest(serviceName, aliasName, functionName);
GetProvisionConfigResponse getProvisionConfigResponse = client.getProvisionConfig(getProvisionConfigRequest);
if (getProvisionConfigResponse.getCurrent() != 0) {
Thread.sleep(1000); // sleep 1s
retryTimes++;
continue;
}
break;
}
assertEquals(true, retryTimes < 30);
} catch (Exception e) {
assertNull(e);
}
}
private void cleanupCustomDomain(String customDomainName) {
DeleteCustomDomainRequest request = new DeleteCustomDomainRequest(customDomainName);
try {
client.deleteCustomDomain(request);
} catch (ClientException e) {
if (!ErrorCodes.DOMAIN_NAME_NOT_FOUND.equals(e.getErrorCode())) {
throw e;
}
}
System.out.println("CustomDomain " + customDomainName + " is deleted");
}
private TriggerMetadata[] listTriggers(String serviceName, String functionName) {
ListTriggersRequest listReq = new ListTriggersRequest(serviceName,
functionName);
ListTriggersResponse listResp = client.listTriggers(listReq);
assertFalse(Strings.isNullOrEmpty(listResp.getRequestId()));
return listResp.getTriggers();
}
private void cleanUpFunctions(String serviceName) {
ListFunctionsRequest listFReq = new ListFunctionsRequest(serviceName);
ListFunctionsResponse listFResp = client.listFunctions(listFReq);
FunctionMetadata[] functions = listFResp.getFunctions();
for (FunctionMetadata function : functions) {
TriggerMetadata[] triggers = listTriggers(serviceName, function.getFunctionName());
cleanUpTriggers(serviceName, function.getFunctionName(), triggers);
System.out.println(
"All triggers for Function " + function.getFunctionName() + " are deleted");
DeleteFunctionRequest deleteFReq = new DeleteFunctionRequest(serviceName,
function.getFunctionName());
client.deleteFunction(deleteFReq);
}
}
private void cleanUpTriggers(String serviceName, String functionName,
TriggerMetadata[] triggers) {
for (TriggerMetadata trigger : triggers) {
DeleteTriggerResponse response = deleteTrigger(serviceName, functionName,
trigger.getTriggerName());
assertTrue(response.isSuccess());
System.out.println("Trigger " + trigger.getTriggerName() + " is deleted");
}
}
private String cleanUpVersions(String serviceName) {
ListVersionsRequest listVersionsReq = new ListVersionsRequest(serviceName);
ListVersionsResponse listVersionResp = client.listVersions(listVersionsReq);
VersionMetaData[] versions = listVersionResp.getVersions();
for (VersionMetaData version : versions) {
DeleteVersionRequest deleteVersionRequest = new DeleteVersionRequest(serviceName,
version.getVersionId());
DeleteVersionResponse response = client.deleteVersion(deleteVersionRequest);
assertTrue(response.isSuccess());
System.out.println("Version " + version.getVersionId() + " is deleted");
}
return (versions.length > 0) ? versions[0].getVersionId() : "0";
}
private void cleanUpAliases(String serviceName) {
ListAliasesRequest listAliasesRequest = new ListAliasesRequest(serviceName);
ListAliasesResponse listAliasesResponse = client.listAliases(listAliasesRequest);
AliasMetaData[] aliases = listAliasesResponse.getAliases();
for (AliasMetaData alias : aliases) {
DeleteAliasRequest deleteAliasRequest = new DeleteAliasRequest(serviceName,
alias.getAliasName());
DeleteAliasResponse response = client.deleteAlias(deleteAliasRequest);
assertTrue(response.isSuccess());
System.out.println(alias.getAliasName() + " is deleted");
}
}
private CreateFunctionResponse createFunction(String functionName) throws IOException {
return createFunction(SERVICE_NAME, functionName);
}
private CreateFunctionResponse createFunction(String serviceName, String functionName) throws IOException {
String source = "exports.handler = function(event, context, callback) {\n" +
" callback(null, 'hello world');\n" +
"};";
byte[] code = Util.createZipByteData("hello_world.js", source);
CreateFunctionRequest createFuncReq = new CreateFunctionRequest(serviceName);
createFuncReq.setFunctionName(functionName);
createFuncReq.setDescription(FUNCTION_DESC_OLD);
createFuncReq.setMemorySize(128);
createFuncReq.setHandler("hello_world.handler");
createFuncReq.setRuntime("nodejs4.4");
Map<String, String> environmentVariables = new HashMap<String, String>();
environmentVariables.put("testKey", "testValue");
createFuncReq.setEnvironmentVariables(environmentVariables);
createFuncReq.setCode(new Code().setZipFile(code));
createFuncReq.setTimeout(10);
CreateFunctionResponse response = client.createFunction(createFuncReq);
assertFalse(Strings.isNullOrEmpty(response.getRequestId()));
assertFalse(Strings.isNullOrEmpty(response.getFunctionId()));
assertEquals(functionName, response.getFunctionName());
assertEquals(FUNCTION_DESC_OLD, response.getDescription());
environmentVariables = response.getEnvironmentVariables();
assertEquals(1, environmentVariables.size());
assertEquals("testValue", environmentVariables.get("testKey"));
assertEquals(functionName, response.getFunctionName());
assertEquals(FUNCTION_DESC_OLD, response.getDescription());
return response;
}
private CreateServiceResponse createService(String serviceName) {
return createService(serviceName, true);
}
private CreateServiceResponse createService(String serviceName, boolean check) {
CreateServiceRequest createSReq = new CreateServiceRequest();
createSReq.setServiceName(serviceName);
createSReq.setDescription(SERVICE_DESC_OLD);
createSReq.setRole(ROLE);
CreateServiceResponse response = client.createService(createSReq);
if (check) {
assertEquals(serviceName, response.getServiceName());
assertFalse(Strings.isNullOrEmpty(response.getRequestId()));
assertFalse(Strings.isNullOrEmpty(response.getServiceId()));
assertEquals(SERVICE_DESC_OLD, response.getDescription());
assertEquals(ROLE, response.getRole());
}
return response;
}
private CreateServiceResponse createVPCService(String serviceName) {
CreateServiceRequest createSReq = new CreateServiceRequest();
createSReq.setServiceName(serviceName);
createSReq.setDescription(SERVICE_DESC_OLD);
createSReq.setRole(ROLE);
createSReq
.setVpcConfig(new VpcConfig(VPC_ID, new String[]{VSWITCH_IDS}, SECURITY_GROUP_ID));
createSReq.setNasConfig(new NasConfig(Integer.parseInt(USER_ID), Integer.parseInt(GROUP_ID),
new NasMountConfig[]{
new NasMountConfig(NAS_SERVER_ADDR, NAS_MOUNT_DIR)
}));
CreateServiceResponse response = client.createService(createSReq);
assertEquals(serviceName, response.getServiceName());
assertFalse(Strings.isNullOrEmpty(response.getRequestId()));
assertFalse(Strings.isNullOrEmpty(response.getServiceId()));
assertEquals(SERVICE_DESC_OLD, response.getDescription());
assertEquals(ROLE, response.getRole());
assertEquals(VPC_ID, response.getVpcConfig().getVpcId());
assertEquals(SECURITY_GROUP_ID, response.getVpcConfig().getSecurityGroupId());
return response;
}
private CreateTriggerResponse createHttpTrigger(String triggerName, HttpAuthType authType,
HttpMethod[] methods) {
return createHttpTriggerWithQualifier(triggerName, "", authType, methods);
}
private CreateTriggerResponse createHttpTriggerWithQualifier(String triggerName,
String qualifier,
HttpAuthType authType, HttpMethod[] methods) {
CreateTriggerRequest createReq = new CreateTriggerRequest(SERVICE_NAME, FUNCTION_NAME);
createReq.setTriggerName(triggerName);
createReq.setTriggerType(TRIGGER_TYPE_HTTP);
createReq.setTriggerConfig(new HttpTriggerConfig(authType, methods));
if (!qualifier.isEmpty()) {
createReq.setQualifier(qualifier);
}
return client.createTrigger(createReq);
}
private CreateTriggerResponse createOssTrigger(String triggerName, String prefix,
String suffix) {
CreateTriggerRequest createTReq = new CreateTriggerRequest(SERVICE_NAME, FUNCTION_NAME);
createTReq.setTriggerName(triggerName);
createTReq.setTriggerType(TRIGGER_TYPE_OSS);
createTReq.setInvocationRole(INVOCATION_ROLE);
createTReq.setSourceArn(OSS_SOURCE_ARN);
createTReq.setTriggerConfig(
new OSSTriggerConfig(new String[]{"oss:ObjectCreated:*"}, prefix, suffix));
CreateTriggerResponse resp = client.createTrigger(createTReq);
try {
// Add some sleep since OSS notifications create is not strongly consistent
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return resp;
}
private DeleteTriggerResponse deleteTrigger(String serviceName, String funcName,
String triggerName) {
DeleteTriggerRequest req = new DeleteTriggerRequest(serviceName, funcName, triggerName);
DeleteTriggerResponse resp = client.deleteTrigger(req);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return resp;
}
private UpdateTriggerResponse updateTrigger(UpdateTriggerRequest req) {
UpdateTriggerResponse resp = client.updateTrigger(req);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return resp;
}
// fetch from OSS url and returns crc64 header value
private String fetchFromURL(String urlString) {
try {
URL url = new URL(urlString);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setConnectTimeout(60 * 1000);
httpConn.setReadTimeout(120 * 1000);
httpConn.connect();
assertEquals(200, httpConn.getResponseCode());
String headerKey = "X-Oss-Hash-Crc64ecma";
Map<String, List<String>> headers = httpConn.getHeaderFields();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
if (null == key || !key.equalsIgnoreCase(headerKey)) {
continue;
}
List<String> values = entry.getValue();
StringBuilder builder = new StringBuilder(values.get(0));
for (int i = 1; i < values.size(); i++) {
builder.append(",");
builder.append(values.get(i));
}
return builder.toString();
}
} catch (Exception e) {
assertFalse(String.format("fetchFromURL %s error: %s", urlString, e.toString()), true);
}
return "";
}
@Test
public void testNewRegions() {
FunctionComputeClient clientHz = new FunctionComputeClient("cn-hangzhou", ACCOUNT_ID,
ACCESS_KEY, SECRET_KEY);
ListServicesResponse lrHz = clientHz.listServices(new ListServicesRequest());
assertTrue(lrHz.getStatus() == HttpURLConnection.HTTP_OK);
FunctionComputeClient clientBj = new FunctionComputeClient("cn-beijing", ACCOUNT_ID,
ACCESS_KEY, SECRET_KEY);
ListServicesResponse lrBj = clientBj.listServices(new ListServicesRequest());
assertTrue(lrBj.getStatus() == HttpURLConnection.HTTP_OK);
}
@Test
public void testCRUD()
throws ClientException, JSONException, NoSuchAlgorithmException, InterruptedException, ParseException, IOException {
testCRUDHelper(true);
}
@Test
public void testCRUDStsToken() throws com.aliyuncs.exceptions.ClientException,
ParseException, InterruptedException, IOException {
client = overrideFCClient(true, false);
testCRUDHelper(false);
}
@Test
public void testCRUDStsTokenHttps() throws com.aliyuncs.exceptions.ClientException,
ParseException, InterruptedException, IOException {
client = overrideFCClient(true, true);
testCRUDHelper(false);
}
private String generateNASPythonCode() {
return "# -*- coding: utf-8 -*-\n"
+ "import logging \n"
+ "import random\n"
+ "import string\n"
+ "import os.path\n"
+ "import shutil\n"
+ "from os import path\n"
+ "\n"
+ "def handler(event, context):\n"
+ " logger = logging.getLogger()\n"
+ " root_dir1 = \"" + NAS_MOUNT_DIR + "\"\n"
+ " logger.info('uid : ' + str(os.geteuid()))\n"
+ " logger.info('gid : ' + str(os.getgid()))\n"
+ " file_name = randomString(6)+'.txt'\n"
+ " dir1 = root_dir1 + '/rzhang-test/'\n"
+ " content = \"NAS here I come\"\n"
+ " os.makedirs(dir1)\n"
+ " fw = open(dir1+file_name, \"w+\")\n"
+ " fw.write(content)\n"
+ " fw.close()\n"
+ " fr = open(dir1+file_name)\n"
+ " line = fr.readline()\n"
+ " if line != content:\n"
+ " return False\n"
+ " fr.close()\n"
+ " os.remove(dir1+file_name)\n"
+ " os.rmdir(dir1)\n"
+ " return True\n"
+ " \n"
+ "def randomString(n):\n"
+ " return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(n))\n";
}
@Test
public void testCreateNASService() throws IOException {
String service_name = SERVICE_NAME + "-nas";
createVPCService(service_name);
// Create a function that uses NAS
String source = generateNASPythonCode();
byte[] data = Util.createZipByteData("main.py", source);
String funcName = FUNCTION_NAME + "-nas";
// create function
createFunction(service_name, funcName, "main.handler", "python2.7", data);
// Invoke the function
InvokeFunctionRequest request = new InvokeFunctionRequest(service_name, funcName);
request.setPayload("".getBytes());
InvokeFunctionResponse response = client.invokeFunction(request);
assertEquals("true", new String(response.getPayload()));
// Cleanups
client.deleteFunction(new DeleteFunctionRequest(service_name, funcName));
client.deleteService(new DeleteServiceRequest(service_name));
}
private void preTestProvisionConfig(String serviceName, String functionName, String aliasName) throws Exception {
// create service
createService(serviceName, false);
// create function
createFunction(serviceName, functionName);
// publish a version
String lastVersion = cleanUpVersions(serviceName);
;
PublishVersionRequest publishVersionRequest = new PublishVersionRequest(serviceName);
PublishVersionResponse publishVersionResponse = client.publishVersion(publishVersionRequest);
assertEquals(String.format("%d", Integer.parseInt(lastVersion) + 1), publishVersionResponse.getVersionId());
//Create a Alias against it
String versionId = publishVersionResponse.getVersionId();
CreateAliasRequest createAliasRequest = new CreateAliasRequest(serviceName, aliasName, versionId);
CreateAliasResponse createAliasResponse = client.createAlias(createAliasRequest);
assertEquals(HttpURLConnection.HTTP_OK, createAliasResponse.getStatus());
assertEquals(versionId, createAliasResponse.getVersionId());
assertEquals(aliasName, createAliasResponse.getAliasName());
}
private void afterTestProvisionConfig(String serviceName) {
cleanUpAliases(serviceName);
cleanUpVersions(serviceName);
cleanUpFunctions(serviceName);
cleanupService(serviceName);
}
@Test
public void testProvisionConfig() {
String serviceName = SERVICE_NAME + UUID.randomUUID().toString().substring(0, 5);
String functionName = "hello_world" + UUID.randomUUID().toString().substring(0, 5);
String aliasName = "myAlias";
try {
preTestProvisionConfig(serviceName, functionName, aliasName);
try {
// create provision config
Integer target = 3;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
provisionConfigRequest.setTarget(target);
PutProvisionConfigResponse provisionConfigResponse = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse.getStatus());
assertEquals(target, provisionConfigResponse.getTarget());
// listProvisionConfig
ListProvisionConfigsRequest listProvisionConfigsRequest = new ListProvisionConfigsRequest();
listProvisionConfigsRequest.setServiceName(serviceName);
listProvisionConfigsRequest.setQualifier(aliasName);
listProvisionConfigsRequest.setLimit(100);
ListProvisionConfigsResponse listProvisionConfigsResponse = client.listProvisionConfigs(listProvisionConfigsRequest);
assertEquals(HttpURLConnection.HTTP_OK, listProvisionConfigsResponse.getStatus());
assertEquals(target, listProvisionConfigsResponse.getProvisionConfigs()[0].getTarget());
} catch (Exception e0) {
assertNull(e0);
} finally {
cleanupProvision(serviceName, aliasName, functionName);
}
} catch (Exception e) {
assertNull(e);
} finally {
afterTestProvisionConfig(serviceName);
}
}
@Test
public void testProvisionConfigWithScheduledAction() {
String serviceName = SERVICE_NAME + UUID.randomUUID().toString().substring(0, 5);
String functionName = "hello_world" + UUID.randomUUID().toString().substring(0, 5);
String aliasName = "myAlias";
try {
preTestProvisionConfig(serviceName, functionName, aliasName);
try {
// create provision config
Integer target = 3;
Integer scheduledActionTarget1 = 5;
Integer scheduledActionTarget2 = 5;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
ScheduledAction[] scheduledActions = new ScheduledAction[2];
scheduledActions[0] = new ScheduledAction("a1", "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget1, "at(2020-10-20T10:10:10Z)");
scheduledActions[1] = new ScheduledAction("a2", "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget2, "cron(0 */30 * * * *)");
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(scheduledActions);
PutProvisionConfigResponse provisionConfigResponse = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse.getStatus());
assertEquals(target, provisionConfigResponse.getTarget());
assertEquals(scheduledActions.length, provisionConfigResponse.getScheduledActions().length);
assertEquals(scheduledActionTarget1, provisionConfigResponse.getScheduledActions()[0].getTarget());
assertEquals(scheduledActionTarget2, provisionConfigResponse.getScheduledActions()[1].getTarget());
// retry 120s for autoScalingLoop
int retryTimes = 0;
while (retryTimes < 120) {
// get provisionConfig
GetProvisionConfigRequest getProvisionConfigRequest = new GetProvisionConfigRequest(serviceName, aliasName, functionName);
GetProvisionConfigResponse getProvisionConfigResponse = client.getProvisionConfig(getProvisionConfigRequest);
if (getProvisionConfigResponse.getCurrent() != scheduledActionTarget2) {
Thread.sleep(1000); // sleep 1s
retryTimes++;
continue;
}
assertEquals(scheduledActionTarget2, getProvisionConfigResponse.getTarget());
assertEquals(scheduledActionTarget2, getProvisionConfigResponse.getCurrent());
assertEquals(scheduledActions.length, provisionConfigResponse.getScheduledActions().length);
assertEquals(scheduledActionTarget1, provisionConfigResponse.getScheduledActions()[0].getTarget());
assertEquals(scheduledActionTarget2, provisionConfigResponse.getScheduledActions()[1].getTarget());
break;
}
assertEquals(true, retryTimes < 120);
// set scheduledActions to null, assert scheduledActions will not be modified
provisionConfigRequest.setScheduledActions(null);
PutProvisionConfigResponse provisionConfigResponse2 = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse2.getStatus());
assertEquals(scheduledActions.length, provisionConfigResponse2.getScheduledActions().length);
// set scheduledActions to [], assert scheduledActions will be modified to empty
provisionConfigRequest.setScheduledActions(new ScheduledAction[0]);
PutProvisionConfigResponse provisionConfigResponse3 = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse3.getStatus());
assertEquals(0, provisionConfigResponse3.getScheduledActions().length);
} catch (Exception e0) {
e0.printStackTrace();
assertNull(e0);
} finally {
cleanupProvision(serviceName, aliasName, functionName);
}
} catch (Exception e) {
e.printStackTrace();
assertNull(e);
} finally {
afterTestProvisionConfig(serviceName);
}
}
@Test
public void testProvisionConfigWithScheduledActionValidate() {
String serviceName = SERVICE_NAME + UUID.randomUUID().toString().substring(0, 5);
String functionName = "hello_world" + UUID.randomUUID().toString().substring(0, 5);
String aliasName = "myAlias";
try {
preTestProvisionConfig(serviceName, functionName, aliasName);
try {
// actionName repeated
scheduledActionValidate1(serviceName, functionName, aliasName);
// utc time format error
scheduledActionValidate2(serviceName, functionName, aliasName);
// scheduleExpression error
scheduledActionValidate3(serviceName, functionName, aliasName);
// actions out of size
scheduledActionValidate4(serviceName, functionName, aliasName);
} catch (Exception e0) {
assertNull(e0);
}
} catch (Exception e) {
assertNull(e);
} finally {
afterTestProvisionConfig(serviceName);
}
}
@Test
public void testProvisionConfigWithTargetTrackingPolicies() {
String serviceName = SERVICE_NAME + UUID.randomUUID().toString().substring(0, 5);
String functionName = "hello_world" + UUID.randomUUID().toString().substring(0, 5);
String aliasName = "myAlias";
try {
preTestProvisionConfig(serviceName, functionName, aliasName);
try {
// create provision config
Integer target = 3;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
TargetTrackingPolicy[] policies = new TargetTrackingPolicy[1];
policies[0] = new TargetTrackingPolicy("p1", "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", "ProvisionedConcurrencyUtilization", new Double(0.6f), 5, 200);
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setTargetTrackingPolicies(policies);
PutProvisionConfigResponse provisionConfigResponse = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse.getStatus());
assertEquals(target, provisionConfigResponse.getTarget());
assertEquals(1, provisionConfigResponse.getTargetTrackingPolicies().length);
assertEquals("p1", provisionConfigResponse.getTargetTrackingPolicies()[0].getName());
assertEquals("2020-10-10T10:10:10Z", provisionConfigResponse.getTargetTrackingPolicies()[0].getStartTime());
assertEquals("2030-10-10T10:10:10Z", provisionConfigResponse.getTargetTrackingPolicies()[0].getEndTime());
assertEquals("ProvisionedConcurrencyUtilization", provisionConfigResponse.getTargetTrackingPolicies()[0].getMetricType());
assertEquals(new Double(0.6f), provisionConfigResponse.getTargetTrackingPolicies()[0].getMetricTarget());
assertEquals(5, provisionConfigResponse.getTargetTrackingPolicies()[0].getMinCapacity().intValue());
assertEquals(200, provisionConfigResponse.getTargetTrackingPolicies()[0].getMaxCapacity().intValue());
// set targetTrackingPolicies to null, assert targetTrackingPolicies will not be modified
provisionConfigRequest.setTargetTrackingPolicies(null);
PutProvisionConfigResponse provisionConfigResponse2 = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse2.getStatus());
assertEquals(1, provisionConfigResponse2.getTargetTrackingPolicies().length);
// set targetTrackingPolicies to [], assert targetTrackingPolicies will be modified to empty
provisionConfigRequest.setTargetTrackingPolicies(new TargetTrackingPolicy[0]);
PutProvisionConfigResponse provisionConfigResponse3 = client.putProvisionConfig(provisionConfigRequest);
assertEquals(HttpURLConnection.HTTP_OK, provisionConfigResponse3.getStatus());
assertEquals(0, provisionConfigResponse3.getTargetTrackingPolicies().length);
} catch (Exception e0) {
e0.printStackTrace();
assertNull(e0);
} finally {
cleanupProvision(serviceName, aliasName, functionName);
}
} catch (Exception e) {
e.printStackTrace();
assertNull(e);
} finally {
afterTestProvisionConfig(serviceName);
}
}
// actionName repeated
private void scheduledActionValidate1(String serviceName, String functionName, String aliasName) {
String actionName = "action1";
try {
// create provision config
Integer target = 3;
Integer scheduledActionTarget1 = 5;
Integer scheduledActionTarget2 = 5;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
ScheduledAction[] scheduledActions = new ScheduledAction[2];
scheduledActions[0] = new ScheduledAction(actionName, "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget1, "at(2020-10-20T10:10:10Z)");
scheduledActions[1] = new ScheduledAction(actionName, "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget2, "cron(0 */30 * * * *)");
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(scheduledActions);
client.putProvisionConfig(provisionConfigRequest);
} catch (ClientException clientException) {
assertEquals("Duplicate action name '" + actionName + "' in ScheduledActions is not allowed",
clientException.getErrorMessage());
}
}
// utc time format error
private void scheduledActionValidate2(String serviceName, String functionName, String aliasName) {
try {
// create provision config
Integer target = 3;
Integer scheduledActionTarget1 = 5;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
ScheduledAction[] scheduledActions = new ScheduledAction[1];
scheduledActions[0] = new ScheduledAction("a1", "2020-10-10T10:10:10",
"2030-10-10T10:10:10Z", scheduledActionTarget1, "at(2020-10-20T10:10:10Z)");
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(scheduledActions);
client.putProvisionConfig(provisionConfigRequest);
} catch (ClientException clientException) {
assertEquals("The StartTime is not in UTC time format (example: '2020-10-10T10:10:10Z', " +
"actual: '2020-10-10T10:10:10')", clientException.getErrorMessage());
}
}
// scheduleExpression error
private void scheduledActionValidate3(String serviceName, String functionName, String aliasName) {
try {
// create provision config
Integer target = 3;
Integer scheduledActionTarget1 = 5;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
ScheduledAction[] scheduledActions = new ScheduledAction[1];
scheduledActions[0] = new ScheduledAction("a1", "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget1, "cron(0s */30 * * * *)");
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(scheduledActions);
client.putProvisionConfig(provisionConfigRequest);
} catch (ClientException clientException) {
assertEquals("The ScheduleExpression should be atTime or cron expression " +
"(example: ['at(2020-10-10T10:10:10Z)', 'cron(0 */30 * * * *)'], actual: 'cron(0s */30 * * * *)')",
clientException.getErrorMessage());
}
}
// actions out of size
private void scheduledActionValidate4(String serviceName, String functionName, String aliasName) {
try {
// create provision config
Integer target = 3;
Integer scheduledActionTarget = 5;
PutProvisionConfigRequest provisionConfigRequest = new PutProvisionConfigRequest(serviceName, aliasName, functionName);
ScheduledAction[] scheduledActions = new ScheduledAction[110];
for (int index = 0; index < 110; index++) {
scheduledActions[index] = new ScheduledAction("action_" + index, "2020-10-10T10:10:10Z",
"2030-10-10T10:10:10Z", scheduledActionTarget, "cron(0 */30 * * * *)");
}
provisionConfigRequest.setTarget(target);
provisionConfigRequest.setScheduledActions(scheduledActions);
client.putProvisionConfig(provisionConfigRequest);
} catch (ClientException clientException) {
assertEquals("ScheduledActions contains too many values (max: 100, actual: 110)",
clientException.getErrorMessage());
}
}
@Test
public void testServiceWithTracingConfig() {
String serviceName = SERVICE_NAME + "-tracing";
String functionName = "hello_world";
JaegerConfig jaegerConfig = new JaegerConfig();
jaegerConfig.setEndpoint(JAEGER_ENDPOINT);
TracingConfig tracingConfig = new TracingConfig();
tracingConfig.setJaegerConfig(jaegerConfig);
try {
// create service with tracingConfig
CreateServiceRequest req = new CreateServiceRequest();
req.setServiceName(serviceName);
req.setTracingConfig(tracingConfig);
CreateServiceResponse resp = client.createService(req);
assertNotNull(resp.getTracingConfig());
assertNotNull(resp.getTracingConfig().getJaegerConfig());
assertEquals(JAEGER_ENDPOINT, resp.getTracingConfig().getJaegerConfig().getEndpoint());
// get service with tracingConfig
GetServiceRequest getServiceRequest = new GetServiceRequest(serviceName);
GetServiceResponse getServiceResponse = client.getService(getServiceRequest);
assertNotNull(getServiceResponse.getTracingConfig());
assertNotNull(getServiceResponse.getTracingConfig().getJaegerConfig());
assertEquals(JAEGER_ENDPOINT, getServiceResponse.getTracingConfig().getJaegerConfig().getEndpoint());
// create function
String source = "exports.handler = function(event, context, callback) {\n" +
" callback(null, context.tracing.openTracingSpanContext + '|' + context.tracing.openTracingSpanBaggages['key']);\n" +
"};";
byte[] code = Util.createZipByteData("hello_world.js", source);
CreateFunctionRequest createFuncReq = new CreateFunctionRequest(serviceName);
createFuncReq.setFunctionName(functionName);
createFuncReq.setDescription(FUNCTION_DESC_OLD);
createFuncReq.setMemorySize(128);
createFuncReq.setHandler("hello_world.handler");
createFuncReq.setRuntime("nodejs4.4");
createFuncReq.setCode(new Code().setZipFile(code));
createFuncReq.setTimeout(10);
CreateFunctionResponse response = client.createFunction(createFuncReq);
assertEquals(functionName, response.getFunctionName());
// invokeFunction with injected span context
InvokeFunctionRequest invokeFunctionRequest = new InvokeFunctionRequest(serviceName, functionName);
invokeFunctionRequest.setHeader(OPENTRACING_SPANCONTEXT, "124ed43254b54966:124ed43254b54966:0:1");
invokeFunctionRequest.setHeader(OPENTRACING_SPANCONTEXT_BAGGAGE_PREFIX + "key", "val");
InvokeFunctionResponse invokeFunctionResponse = client.invokeFunction(invokeFunctionRequest);
String payload = new String(invokeFunctionResponse.getPayload());
assertTrue(payload.contains("124ed43254b54966"));
assertTrue(payload.contains("val"));
// update service and disable tracingConfig
UpdateServiceRequest updateServiceRequest = new UpdateServiceRequest(serviceName);
updateServiceRequest.setTracingConfig(new TracingConfig());
UpdateServiceResponse updateServiceResponse = client.updateService(updateServiceRequest);
assertNotNull(updateServiceResponse.getTracingConfig());
assertNull(updateServiceResponse.getTracingConfig().getType());
assertNull(updateServiceResponse.getTracingConfig().getParams());
} catch (Exception e) {
e.printStackTrace();
// assert case fail
assertNull(e);
} finally {
cleanUpFunctions(serviceName);
cleanupService(serviceName);
}
}
@Test
public void testServiceWithRequestMetrics() {
String serviceName = SERVICE_NAME + "-requestMetrics";
LogConfig logConfig = new LogConfig(LOG_PROJECT, LOG_STORE, true);
try {
// create service with enableRequestMetrics
CreateServiceRequest req = new CreateServiceRequest();
req.setServiceName(serviceName);
req.setRole(ROLE);
req.setLogConfig(logConfig);
CreateServiceResponse resp = client.createService(req);
assertNotNull(resp.getLogConfig());
assertTrue(resp.getLogConfig().getEnableRequestMetrics());
assertFalse(resp.getLogConfig().getEnableInstanceMetrics());
// get service
GetServiceRequest getServiceRequest = new GetServiceRequest(serviceName);
GetServiceResponse getServiceResponse = client.getService(getServiceRequest);
assertNotNull(getServiceResponse.getLogConfig());
assertTrue(getServiceResponse.getLogConfig().getEnableRequestMetrics());
assertFalse(getServiceResponse.getLogConfig().getEnableInstanceMetrics());
// update service and disable requestMetrics
logConfig.setEnableRequestMetrics(false);
UpdateServiceRequest updateServiceRequest = new UpdateServiceRequest(serviceName);
updateServiceRequest.setLogConfig(logConfig);
UpdateServiceResponse updateServiceResponse = client.updateService(updateServiceRequest);
assertNotNull(updateServiceResponse.getLogConfig());
assertEquals(LOG_PROJECT, updateServiceResponse.getLogConfig().getProject());
assertEquals(LOG_STORE, updateServiceResponse.getLogConfig().getLogStore());
assertFalse(updateServiceResponse.getLogConfig().getEnableRequestMetrics());
assertFalse(updateServiceResponse.getLogConfig().getEnableInstanceMetrics());
// update service and disable logs
logConfig = new LogConfig("", "", false);
updateServiceRequest = new UpdateServiceRequest(serviceName);
updateServiceRequest.setLogConfig(logConfig);
updateServiceResponse = client.updateService(updateServiceRequest);
assertNotNull(updateServiceResponse.getLogConfig());
assertEquals("", updateServiceResponse.getLogConfig().getProject());
assertEquals("", updateServiceResponse.getLogConfig().getLogStore());
assertFalse(updateServiceResponse.getLogConfig().getEnableRequestMetrics());
assertFalse(updateServiceResponse.getLogConfig().getEnableInstanceMetrics());
} catch (Exception e) {
e.printStackTrace();
// assert case fail
assertNull(e);
} finally {
cleanUpFunctions(serviceName);
cleanupService(serviceName);
}
}
@Test
public void testServiceWithRequestMetricsAndInstanceMetrics() {
String serviceName = SERVICE_NAME + "-instanceMetrics";
LogConfig logConfig = new LogConfig(LOG_PROJECT, LOG_STORE, true, true, NONE);