我的目标(背景信息)
我想在 cumulocity 上开发一个 java 微服务。它应该能够执行以下操作:
我会将“112233”发送到微服务,如下所示:
https://myTenant.cumulocity.com/service/my-application-name/decode?data=112233
然后,微服务应将数据拆分为“11”用于第一次测量,“22”用于第二次测量,依此类推。这些测量结果将发布到 cumulocity。
我的问题
我现在一直在获取Hello, microservice tutorial上类。我无法将微服务(zip 文件)部署到 cumulocity。
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(我是管理员用户。)
我还尝试通过网站上传 zip 文件,这创建了 HOSTED
应用程序而不是 MICROSERVICE
。通过 POST 请求将我的 zip 上传到 HOSTED
应用程序实际上可以工作(我显然不需要)。
我怀疑我收到“访问被拒绝”错误,因为 cumulocity 认为我上传了 HOSTED
申请MICROSERVICE
。
到目前为止我做了什么
代码端
我下载了 hello-world-microservice example来自 cumulocity bitbucket 开发分支。 (此代码在默认分支上不可用)。
我将 cumulocity 版本更改为 9.3.0
,似乎只有这个版本存在。
HelloWorldMain.java 未经编辑
这是我的 cumulocity.json list 文件:(角色没有区别)
{
"apiVersion":"1",
"type":"MICROSERVICE",
"version":"@project.version@",
"availability":"PRIVATE",
"provider":{
"name":"Cumulocity GmbH"
},
"isolation":"MULTI_TENANT",
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"livenessProbe":{
"httpGet":{
"path":"/health",
"port":80
},
"initialDelaySeconds":15,
"periodSeconds":10
},
"readinessProbe":{
"httpGet":{
"path":"/health",
"port":80
}
}
}
这是我的application.properties文件
application.name=my-application-name
server.port=80
C8Y.baseURL=https://myTenant.cumulocity.com
C8Y.bootstrap.tenant=myTenant
C8Y.bootstrap.user=servicebootstrap_my-application-name
C8Y.bootstrap.password={SECRET_BOOTSTRAP_PASSW}
C8Y.user={MY_USERNAME}
C8Y.password={SECRET_PASSW}
C8Y.bootstrap.register=true
C8Y.microservice.isolation=MULTI_TENANT
C8Y.bootstrap.initialDelay=10000
积聚城侧
我成功创建一个微服务应用程序,
获取https://myTenant.cumulocity.com/application/applications/5886返回:
{
"availability":"PRIVATE",
"id":"5886",
"key":"my-application-key",
"manifest":{
"imports":[
],
"noAppSwitcher":true
},
"name":"my-application-name",
"owner":{
"self":"https://myTenant.cumulocity.com/tenant/tenants/myTenant",
"tenant":{
"id":"myTenant"
}
},
"requiredRoles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"roles":[
"ROLE_APPLICATION_MANAGEMENT_ADMIN",
"ROLE_MEASUREMENT_ADMIN",
"ROLE_INVENTORY_ADMIN"
],
"self":"https://myTenant.cumulocity.com/application/applications/5886",
"type":"MICROSERVICE"
}
我也成功订阅此应用程序。
当我尝试将 zip 文件上传到 cumulocity 时,出现以下错误:
"error":"security/Forbidden","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Access is denied"}
(上传到 HOSTED
类型的应用程序工作正常,但我不希望这样。)
note: I also tried to use the microservice deploy script, this gave the same result as doing everything manually.
尝试在本地运行
由于我无法让它在 cumulocity 平台上工作,所以我尝试通过 docker 在本地运行它。我用这个命令运行它:
docker run -e "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" 10aa0b73ddb3
note: I had to add the "C8Y_MICROSERVICE_ISOLATION=MULTI_TENANT" environment variable. if I didn't add this, I'd get credential/permission issues. This seems weird to me, since all other info is read from the application.properties file except for this one.
在本地 docker 上运行此镜像时没有出现任何错误。
根据Hello, microservice tutorial ,我应该可以请求curl -H "Authorization: {AUTHORIZATION}" https://myTenant.cumulocity.com/service/my-application-name/hello?who=me
这将返回:
{"error":"microservice/Not Found","info":"https://www.cumulocity.com/guides/reference-guide/#error_reporting","message":"Microservice my-application-name not found."}
回到问题
还有其他人在 cumulocity 上设置微服务时遇到困难吗?
有什么事情是我完全监督的吗?
最佳答案
微服务托管需要分配给您的租户,否则它将无法工作,并且在这种情况下 API 将返回禁止。因此,您的用户可能没有问题,但您的租户未激活该功能。
关于java - Cumulocity微服务部署: access is denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49818943/