/**
 * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gravitee.gateway.standalone.node;

import io.gravitee.common.component.LifecycleComponent;
import io.gravitee.common.node.AbstractNode;
import io.gravitee.common.utils.UUIDGenerator;
import io.gravitee.gateway.core.Reactor;
import io.gravitee.gateway.standalone.vertx.VertxEmbeddedContainer;
import io.gravitee.repository.management.api.EventRepository;
import io.gravitee.repository.management.model.Event;
import io.gravitee.repository.management.model.EventType;

import java.util.*;

/**
 * @author David BRASSELY (brasseld at gmail.com)
 */
public class GatewayNode extends AbstractNode {

    @Override
    public String name() {
        return "Gravitee.io - Gateway";
    }

    @Override
    protected List<Class<? extends LifecycleComponent>> getLifecycleComponents() {
        List<Class<? extends LifecycleComponent>> components = new ArrayList<>();

        components.add(Reactor.class);
        components.add(VertxEmbeddedContainer.class);

        return components;
    }

    @Override
    protected void doStart() throws Exception {
        super.doStart();
        sendEvent(EventType.START_GATEWAY);
    }

    @Override
    protected void doStop() throws Exception {
        sendEvent(EventType.STOP_GATEWAY);
        super.doStop();
    }

    private void sendEvent(EventType eventType) {
        Event event = new Event();
        event.setId(UUIDGenerator.generate().toString());
        event.setType(eventType);
        event.setCreatedAt(new Date());
        Map<String, String> properties = new HashMap<>();
        properties.put("gateway_id", this.id());
        event.setProperties(properties);
        try {
            applicationContext.getBean(EventRepository.class).create(event);
        } catch (Exception ex) {
            LOGGER.error("Unexpected error while sending a {} event into the repository", eventType, ex);
        }
    }
}

@@ -771,16 +771,56 @@
 ctNode;%0A
+import io.gravitee.common.util.Version;%0A
 import i
@@ -1145,135 +1145,461 @@
 pe;%0A
-%0Aimport java.util.*;%0A%0A/**%0A * @author David BRASSELY (brasseld at gmail.com)%0A */%0Apublic class GatewayNode extends AbstractNode %7B
+import org.springframework.beans.factory.annotation.Value;%0A%0Aimport java.net.InetAddress;%0Aimport java.net.UnknownHostException;%0Aimport java.util.*;%0Aimport java.util.stream.Collectors;%0A%0A/**%0A * @author David BRASSELY (brasseld at gmail.com)%0A */%0Apublic class GatewayNode extends AbstractNode %7B%0A%0A    private static final String TAGS_PROP = %22tags%22;%0A    private static final String TAGS_DELIMITER = %22,%22;%0A%0A    @Value(%22$%7Btags:%7D%22)%0A    private String propertyTags;
 %0A%0A  
@@ -2568,313 +2568,1138 @@
 ut(%22
-gateway_id%22, this.id());%0A        event.setProperties(properties);%0A        try %7B%0A            applicationContext.getBean(EventRepository.class).create(event);%0A        %7D catch (Exception ex) %7B%0A            LOGGER.error(%22Unexpected error while sending a %7B%7D event into the repository%22, eventType, ex);%0A        %7D
+id%22, this.id());%0A        if (eventType == EventType.START_GATEWAY) %7B%0A            properties.put(%22version%22, Version.RUNTIME_VERSION.toString());%0A            properties.put(%22tags%22, tags().stream().collect(Collectors.joining(TAGS_DELIMITER)));%0A            try %7B%0A                properties.put(%22hostname%22, InetAddress.getLocalHost().getHostName());%0A                properties.put(%22ip%22, InetAddress.getLocalHost().getHostAddress());%0A            %7D catch (UnknownHostException uhe) %7B%7D%0A        %7D%0A        event.setProperties(properties);%0A        try %7B%0A            applicationContext.getBean(EventRepository.class).create(event);%0A        %7D catch (Exception ex) %7B%0A            LOGGER.error(%22Unexpected error while sending a %7B%7D event into the repository%22, eventType, ex);%0A        %7D%0A    %7D%0A%0A    public List%3CString%3E tags() %7B%0A        final String systemPropertyTags = System.getProperty(TAGS_PROP);%0A        final String tags = systemPropertyTags == null ? propertyTags : systemPropertyTags;%0A        return (tags == null %7C%7C tags.isEmpty()) ?%0A                Collections.EMPTY_LIST :%0A                Arrays.asList(tags.trim().split(TAGS_DELIMITER));
 %0A   

Add more informations when node is starting