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

Add Asset interface #5

Merged
merged 4 commits into from
Nov 29, 2024
Merged
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
10 changes: 10 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Category
- [ ] New feature
- [ ] Bug fix
- [ ] Improvement
- [ ] Refactor
- [ ] etc

### Description

### Known issue
2 changes: 1 addition & 1 deletion deploy/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.1
version: 0.0.2
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
15 changes: 12 additions & 3 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enabled: true
developer: false
grpc: true
scheduler: false
worker: false
worker: true
rest: false
name: inventory-v2
image:
Expand Down Expand Up @@ -100,8 +100,17 @@ application_scheduler:

# Overwrite worker config
application_worker:
QUEUES: {}
WORKERS: {}
QUEUES:
inventory_q:
backend: spaceone.core.queue.redis_queue.RedisQueue
host: redis
port: 6379
channel: inventory_job
WORKERS:
inventory_worker:
backend: spaceone.core.scheduler.worker.BaseWorker
queue: inventory_q
pool: 1

##########################
# local sidecar
Expand Down
32 changes: 32 additions & 0 deletions src/spaceone/inventory_v2/conf/collector_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
######################################################################
# ************ Very Important ************
#
# This is resource map for collector
# If you add new service and manager for specific RESOURCE_TYPE,
# add here for collector
######################################################################

RESOURCE_MAP = {
"inventory.CloudService": ("CloudServiceService", "CloudServiceManager"),
"inventory.CloudServiceType": (
"CloudServiceTypeService",
"CloudServiceTypeManager",
),
"inventory.Region": ("RegionService", "RegionManager"),
"inventory.ErrorResource": ("CollectorService", "CollectingManager"),
}


OP_MAP = {"=": "eq", ">=": "gte", "<=": "lte", ">": "gt", "<": "lt", "!=": "not"}

DB_QUEUE_NAME = "db_q"

NOT_COUNT = 0
CREATED = 1
UPDATED = 2
ERROR = 3

JOB_TASK_STAT_EXPIRE_TIME = 3600 # 1 hour
WATCHDOG_WAITING_TIME = 30 # wait 30 seconds, before watchdog works

MAX_MESSAGE_LENGTH = 2000
13 changes: 10 additions & 3 deletions src/spaceone/inventory_v2/conf/global_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@
"identity": "grpc://identity:50051",
"monitoring": "grpc://monitoring:50051",
"file_manager": "grpc://file-manager:50051",
"secret": "grpc://secret:50051"
"secret": "grpc://secret:50051",
},
}
}

# Queue Settings
QUEUES = {
"inventory_q": {
"backend": "spaceone.core.queue.redis_queue.RedisQueue",
"host": "redis",
"port": 6379,
"channel": "inventory_job",
},
}
# Scheduler Settings
QUEUES = {}
SCHEDULERS = {}
WORKERS = {}
TOKEN_INFO = {}
3 changes: 2 additions & 1 deletion src/spaceone/inventory_v2/error/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from spaceone.inventory_v2.error.region import *
from spaceone.inventory_v2.error.region import *
from spaceone.inventory_v2.error.collector import *
5 changes: 5 additions & 0 deletions src/spaceone/inventory_v2/error/asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from spaceone.core.error import *


class ERROR_RESOURCE_ALREADY_DELETED(ERROR_INVALID_ARGUMENT):
_message = "{resource_type} has already been deleted. ({resource_id})"
105 changes: 105 additions & 0 deletions src/spaceone/inventory_v2/error/collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from spaceone.core.error import *


class ERROR_NO_COLLECTOR(ERROR_BASE):
_message = "{collector_id} does not exist in {domain_id}"


class ERROR_COLLECTOR_STATE(ERROR_BASE):
_message = "collector state is {state}"


class ERROR_INIT_PLUGIN_FAILURE(ERROR_BASE):
_message = "Fail to init plugin, params={params}"


class ERROR_VERIFY_PLUGIN_FAILURE(ERROR_BASE):
_message = "Fail to verify plugin, params={params}"


class ERROR_NO_PLUGIN_PARAMETER(ERROR_BASE):
_message = "parameter: {param} is required"


class ERROR_TOKEN_AUTHENTICATION_FAILURE(ERROR_BASE):
_message = "A access token or refresh token is invalid."


class ERROR_AUTHENTICATION_FAILURE_PLUGIN(ERROR_BASE):
_message = (
"External plugin authentication exception. (plugin_error_message={message})"
)


class ERROR_JOB_STATE_CHANGE(ERROR_BASE):
_message = "Job {job_id} state change: {status} -> {action}"


class ERROR_JOB_TASK_STATE_CHANGE(ERROR_BASE):
_message = "Job task {job_task_id} state change: {status} -> {action}"


class ERROR_COLLECT_FILTER(ERROR_BASE):
_message = "collect failed, plugin_info: {plugin_info}, filter: {param}"


class ERROR_COLLECTOR_SECRET(ERROR_BASE):
_message = "collect failed, plugin_info: {plugin_info}, secret_id: {param}"


class ERROR_JOB_UPDATE(ERROR_BASE):
_message = "job update failed, param={param}"


class ERROR_COLLECTOR_COLLECTING(ERROR_BASE):
_message = "collecting failed, plugin_info: {plugin_info}, filter: {filter}"


class ERROR_COLLECT_CANCELED(ERROR_BASE):
_message = "collecting canceled, job_id: {job_id}"


class ERROR_UNSUPPORTED_RESOURCE_TYPE(ERROR_BASE):
_message = "collector can not find resource_type: {resource_type}"


class ERROR_UNSUPPORTED_FILTER_KEY(ERROR_BASE):
_message = "request unsupported filter_key {filter_key} : {filter_value}"


class ERROR_COLLECT_INITIALIZE(ERROR_BASE):
_message = "failed on stage {stage}, params: {params}"


class ERROR_INVALID_PLUGIN_VERSION(ERROR_INVALID_ARGUMENT):
_message = (
"Plugin version is invalid. (plugin_id = {plugin_id}, version = {version})"
)


class ERROR_NOT_ALLOWED_PLUGIN_ID(ERROR_INVALID_ARGUMENT):
_message = "Changing plugin_id is not allowed. (old_plugin_id = {old_plugin_id}, new_plugin_id = {new_plugin_id})"


class ERROR_WRONG_PLUGIN_SETTINGS(ERROR_BASE):
_message = "The plugin settings is incorrect. (key = {key})"


class ERROR_INVALID_PLUGIN_OPTIONS(ERROR_INTERNAL_API):
_message = "The options received from the plugin is invalid. (reason = {reason})"


class ERROR_RESOURCE_KEYS_NOT_DEFINED(ERROR_BASE):
_message = "{resource_type} manager does not define resource_keys field"


class ERROR_TOO_MANY_MATCH(ERROR_BASE):
_message = "The same resource exists. (match_key = {match_key}, matched_resources = {resources}, more = {more})"


class ERROR_UNSUPPORTED_SCHEDULE(ERROR_BASE):
_message = "supported schedules: {supported}, requested: {requested}"


class ERROR_NOT_ALLOWED_SECRET_ID(ERROR_BASE):
_message = "Not allowed secret_id: {secret_id}"
5 changes: 3 additions & 2 deletions src/spaceone/inventory_v2/info/region_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from spaceone.api.inventory.v2 import region_pb2
from spaceone.core.pygrpc.message_type import *
from spaceone.core import utils
from spaceone.inventory_v2.model.region_model import Region
from spaceone.inventory_v2.model.region.region_model import Region

__all__ = ["RegionInfo", "RegionsInfo"]

_LOGGER = logging.getLogger(__name__)


def RegionInfo(region_vo: Region, minimal=False):
info = {
"region_id": region_vo.region_id,
Expand All @@ -35,4 +36,4 @@ def RegionsInfo(region_vos, total_count, **kwargs):
return region_pb2.RegionsInfo(
results=list(map(functools.partial(RegionInfo, **kwargs), region_vos)),
total_count=total_count,
)
)
4 changes: 0 additions & 4 deletions src/spaceone/inventory_v2/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
from spaceone.core.pygrpc.server import GRPCServer

_all_ = ["app"]

app = GRPCServer()
56 changes: 56 additions & 0 deletions src/spaceone/inventory_v2/interface/grpc/metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from spaceone.core.pygrpc import BaseAPI
from spaceone.api.inventory_v2.v1 import metric_pb2, metric_pb2_grpc
from spaceone.inventory.service.metric_service import MetricService


class Metric(BaseAPI, metric_pb2_grpc.MetricServicer):
pb2 = metric_pb2
pb2_grpc = metric_pb2_grpc

def create(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.create(params)
return self.dict_to_message(response)

def update(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.update(params)
return self.dict_to_message(response)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
metric_svc.delete(params)
return self.empty()

def run(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
metric_svc.run(params)
return self.empty()

def test(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.test(params)
return self.dict_to_message(response)

def get(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.get(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.list(params)
return self.dict_to_message(response)

def stat(self, request, context):
params, metadata = self.parse_request(request, context)
metric_svc = MetricService(metadata)
response: dict = metric_svc.stat(params)
return self.dict_to_message(response)
26 changes: 26 additions & 0 deletions src/spaceone/inventory_v2/interface/grpc/metric_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from spaceone.core.pygrpc import BaseAPI
from spaceone.api.inventory_v2.v1 import metric_data_pb2, metric_data_pb2_grpc
from spaceone.inventory.service.metric_data_service import MetricDataService


class MetricData(BaseAPI, metric_data_pb2_grpc.MetricDataServicer):
pb2 = metric_data_pb2
pb2_grpc = metric_data_pb2_grpc

def list(self, request, context):
params, metadata = self.parse_request(request, context)
metric_data_svc = MetricDataService(metadata)
response: dict = metric_data_svc.list(params)
return self.dict_to_message(response)

def analyze(self, request, context):
params, metadata = self.parse_request(request, context)
metric_data_svc = MetricDataService(metadata)
response: dict = metric_data_svc.analyze(params)
return self.dict_to_message(response)

def stat(self, request, context):
params, metadata = self.parse_request(request, context)
metric_data_svc = MetricDataService(metadata)
response: dict = metric_data_svc.stat(params)
return self.dict_to_message(response)
44 changes: 44 additions & 0 deletions src/spaceone/inventory_v2/interface/grpc/metric_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from spaceone.core.pygrpc import BaseAPI
from spaceone.api.inventory_v2.v1 import metric_example_pb2, metric_example_pb2_grpc
from spaceone.inventory.service.metric_example_service import MetricExampleService


class MetricExample(BaseAPI, metric_example_pb2_grpc.MetricExampleServicer):
pb2 = metric_example_pb2
pb2_grpc = metric_example_pb2_grpc

def create(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
response: dict = metric_example_svc.create(params)
return self.dict_to_message(response)

def update(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
response: dict = metric_example_svc.update(params)
return self.dict_to_message(response)

def delete(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
metric_example_svc.delete(params)
return self.empty()

def get(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
response: dict = metric_example_svc.get(params)
return self.dict_to_message(response)

def list(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
response: dict = metric_example_svc.list(params)
return self.dict_to_message(response)

def stat(self, request, context):
params, metadata = self.parse_request(request, context)
metric_example_svc = MetricExampleService(metadata)
response: dict = metric_example_svc.stat(params)
return self.dict_to_message(response)
Empty file.
Empty file.
Loading
Loading