public static ApplicationId toApplicationId(ApplicationInstanceReference appRef) {

        String appNameStr = appRef.asString();
        String[] appNameParts = appNameStr.split(":");

        // Env, region and instance seems to be optional due to the hardcoded config server app
        // Assume here that first two are tenant and application name.
        if (appNameParts.length == 2) {
            return ApplicationId.from(TenantName.from(appNameParts[0]),
                    ApplicationName.from(appNameParts[1]),
                    InstanceName.defaultName());
        }

        // Other normal application should have 5 parts.
        if (appNameParts.length != 5)  {
            throw new IllegalArgumentException("Application reference not valid (not 5 parts): " + appRef);
        }

        return ApplicationId.from(TenantName.from(appNameParts[0]),
                ApplicationName.from(appNameParts[1]),
                InstanceName.from(appNameParts[4]));
    }
@Test
    public void applicationid_from_zone_confg_server_appref_is_working() throws Exception {
        ApplicationId appId = OrchestratorUtil.toApplicationId(APPREF_2);
        Assert.assertEquals(ApplicationId.from(
                TenantName.from("hosted-vespa"),
                ApplicationName.from("zone-config-servers"),
                InstanceName.defaultName()),appId);
    }