package org.zstack.identity;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.zstack.core.componentloader.PluginRegistry;
import org.zstack.header.exception.CloudRuntimeException;
import org.zstack.header.managementnode.PrepareDbInitialValueExtensionPoint;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
public class SystemIdentityResourceGenerator implements PrepareDbInitialValueExtensionPoint {
    @Autowired
    private PluginRegistry pluginRgty;

    public void generate() {
        if (StringUtils.isEmpty(IdentityGlobalProperty.IDENTITY_INIT_TYPE)) {
            for (IdentityResourceGenerateExtensionPoint ext : pluginRgty.getExtensionList(IdentityResourceGenerateExtensionPoint.class)) {
                ext.prepareResources();
            }

            return;
        }

        Map<String, List<IdentityResourceGenerateExtensionPoint>> extensionMap = new HashMap<>();
        for (IdentityResourceGenerateExtensionPoint ext : pluginRgty.getExtensionList(IdentityResourceGenerateExtensionPoint.class)) {
            extensionMap.putIfAbsent(ext.getIdentityType(), new ArrayList<>());
            extensionMap.get(ext.getIdentityType()).add(ext);
        }

        for (String identityInitType : IdentityGlobalProperty.IDENTITY_INIT_TYPE.split(",")) {
            identityInitType = identityInitType.trim();
            List<IdentityResourceGenerateExtensionPoint> extensionPoints = extensionMap.get(identityInitType);

            if (extensionPoints != null && !extensionPoints.isEmpty()) {
                for (IdentityResourceGenerateExtensionPoint ext : extensionPoints) {
                    ext.prepareResources();
                }
            } else {
                throw new CloudRuntimeException(String.format("Unknown recognized identity init type %s", identityInitType));
            }
        }
    }

    @Override
    public void prepareDbInitialValue() {
        generate();
    }
}

@@ -447,16 +447,88 @@
 onPoint;
+%0Aimport org.zstack.utils.Utils;%0Aimport org.zstack.utils.logging.CLogger;
 %0A%0Aimport
@@ -782,16 +782,115 @@
 Point %7B%0A
+    private static final CLogger logger = Utils.getLogger(SystemIdentityResourceGenerator.class);%0A%0A
     @Aut
@@ -2178,39 +2178,20 @@
     
-throw new CloudRuntimeException
+logger.debug
 (Str

Print debug message instead of abort mn starting